Definition :
In PHP Array function the xtract() function imports variables into the current symbol table from an array.
This function basically creates variables from an associative array. This is typically done by using the array keys as variable names and their corresponding values as the variable values.
Syntax
The basic syntax of the extract() function is given with:
extract(array, extract_rules, prefix)
The extract()
function accepts the following parameters.
Parameter | Description |
---|---|
array | Required. Specifies an array to use. |
flags |
Optional. Specifies how invalid or numeric keys and collisions are treated. This parameter can take one of the following values:
If this parameter is not specified, it is assumed to be |
prefix |
Optional. Specifies the prefix string. Prefixes are automatically separated from the array key by an underscore ( This parameter is only required if flags is set to any of these values |
Example1 : Below example shows the extract() function in action.
Output :
Example2: following example shows how to prevent overwriting of existing variable if a collision occurs.
Output :