Home >Backend Development >PHP Tutorial >PHP extract() function usage php array splitting
In action.php, just use the extract() function to extract the $_POST global data: action.php
Explanation in php manual: extract (PHP 4, PHP 5) extract — Import variables from an array into the current symbol table Instructions int extract (array $var_array [, int $extract_type [, string $prefix ]] ) This function is used to import variables from the array into the current symbol table. Accepts the associative array var_array as argument and uses the key name as the variable name and the value as the variable value. For each key/value pair a variable is created in the current symbol table, affected by the extract_type and prefix parameters. Note: Since version 4.0.5 this function returns the number of variables extracted. Note: EXTR_IF_EXISTS and EXTR_PREFIX_IF_EXISTS were introduced in version 4.2.0. Note: EXTR_REFS was introduced in version 4.3.0. extract() checks each key name to see if it can be used as a legal variable name, and also checks for conflicts with existing variable names in the symbol table. The treatment of illegal/numeric and conflicting key names will be determined by the extract_type parameter. Can be one of the following values:
The output of the above example: blue, large, sphere, medium $size is not overridden because EXTR_PREFIX_SAME is specified, which causes $wddx_size to be built. If EXTR_SKIP is specified, $wddx_size will not be created either. EXTR_OVERWRITE will make $size have the value "medium" and EXTR_PREFIX_ALL will create new variables $wddx_color, $wddx_size and $wddx_shape. Associative arrays must be used, numerically indexed arrays will not produce results unless EXTR_PREFIX_ALL or EXTR_PREFIX_INVALID is used. |