Home>Article>Backend Development> Detailed explanation and examples of PHP array processing function extract
php extract function uses the array key name as the variable name and the array key value as the variable value. This function can handle form submission and insert into the database. The article explains to you the basic usage and examples of the extract function. Friends who need it can refer to
php array processing function extract
extract function is used to extract data from an array. Variables are imported into the current symbol table
Basic syntax
int extract ( array &$var_array [, int $extract_type = EXTR_OVERWRITE [, string $prefix = NULL ]] )
This function is used to import variables from the array into the current symbol table. Each key name is checked to see if it can be used as a legal variable name, and is also checked for conflicts with existing variable names in the symbol table.
Parameter introduction:
Parameter | Description |
---|---|
var_array | Required. Specifies the array to use. An associative array. This function treats the key name as the variable name and the value as the variable's value. For each key/value pair a variable is created in the current symbol table, affected by the extract_type and prefix parameters. Associative arrays must be used, numerically indexed arrays will not produce results unless EXTR_PREFIX_ALL or EXTR_PREFIX_INVALID is used. |
extract_type | Optional. The extract() function will check whether each key name is a legal variable name, and also checks whether it conflicts with an existing variable name in the symbol table. The handling of illegal and conflicting key names will be determined based on this parameter. Possible values:
|
prefix | Optional. Note that prefix is only required if the value of extract_type is EXTR_PREFIX_SAME, EXTR_PREFIX_ALL, EXTR_PREFIX_INVALID or EXTR_PREFIX_IF_EXISTS. If the result after appending the prefix is not a legal variable name, it will not be imported into the symbol table. An underscore is automatically added between the prefix and the array key name. |
Return value
Returns the number of variables successfully imported into the symbol table.
Example:
"blue", "size" => "medium", "shape" => "sphere" ); extract($var_array, EXTR_PREFIX_SAME, "wddx"); echo " $color , $size , $shape , $wddx_size
"; ?>
Run result:
blue, large, sphere, medium
and above That’s the entire content of this article, I hope it will be helpful to everyone’s study.
PHP realizes third-party instant access to logistics updates
PHP method to implement multi-dimensional array sorting according to a certain key value
PHP method to implement email sending instance based on SMTP protocol
The above is the detailed content of Detailed explanation and examples of PHP array processing function extract. For more information, please follow other related articles on the PHP Chinese website!