The built-in PHP extract() function is used for importing variables from an array into the current symbol table.
It takes an associative array and treat keys as variable names and values as variable values. For each key/value pair it creates a variable in the current symbol table, subject to extract_type and prefix parameters.
Syntax
extract($array, $extract_type, $prefix)
Parameter Details
Sr.No | Parameter & Description |
---|---|
1 | array(Required) It specifies an array |
2 | extract_type(Optional) . The extract() function checks for invalid variable names and collisions with existing variable names. This parameter specifies how invalid and colliding names are treated.Possible values −
|
3 | prefix(Optional) If EXTR_PREFIX_SAME, EXTR_PREFIX_ALL, EXTR_PREFIX_INVALID or EXTR_PREFIX_IF_EXISTS are used in the extract_rules parameter, a specified prefix is required. This parameter specifies the prefix. The prefix is automatically separated from the array key by an underscore character. |
Return Value
Example
<?php $size = "large"; $input = array("color" => "blue", "size" => "medium", "shape" => "sphere"); extract($input, EXTR_PREFIX_SAME, "bbcx"); echo "$color, $size, $shape, $bbcx_size"; ?>
Output
blue, large, sphere, medium
Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.