Array Assignment: Array conversion to variable assignment function extract (Array,type,prefix) and its compact function

Source: Internet
Author: User
Tags array compact numeric key variables variable valid

The PHP extract () function imports variables from the array into the current symbol table.   For each element in the array, the key name is used for the variable name, and the key value is used for the variable value.   The second parameter type specifies how the extract () function treats such a conflict when a variable already exists and an element with the same name is in the array. This function returns the number of variables that were successfully set.
Edit this paragraph syntax

Parameters Describe
Array Necessary. Specify the input to use.
extract_rules handling of illegal, numeric, and conflicting key names is determined according to this parameter. Can be one of the following values:
Possible values: Extr_overwrite-Default. If there is a conflict, overwrite the existing variable.
Extr_skip-If there is a conflict, the existing variable is not overwritten. (ignores elements of the same name in the array)
Extr_prefix_same-If there is a conflict, prefix the variable name PREFIX. Since PHP 4.0.5, this also includes processing of digital indexes.
Extr_prefix_all-Prefix all variable names PREFIX (third argument).
Extr_prefix_invalid-prefix PREFIX only for illegal or numeric variable names. This tag is a new addition to PHP 4.0.5.
Extr_if_exists-overwrites their values only if they already have a variable of the same name in the current symbol table. Nothing else is to be dealt with. You can use an instance where you have defined a set of valid variables and then extract the values from an array such as $_request to overwrite these variables. This tag is a new addition to PHP 4.2.0.
Extr_prefix_if_exists-Creates a variable name with a prefix appended to it only if there is already a variable with the same name in the current symbol table. This tag is a new addition to PHP 4.2.0.
Extr_refs-Extracts a variable as a reference. This is a powerful indication that the imported variable still references the value of the Var_array parameter. This flag can be used alone or in conjunction with any other flag in Extract_type. This tag is a new addition to PHP 4.3.0.
Prefix Optional. Please note that prefix is required only if the Extract_type value is Extr_prefix_same,extr_prefix_all,extr_prefix_invalid or extr_prefix_if_exists. If the result appended with a prefix is not a valid variable name, it will not be imported into the symbol table.
An underscore is automatically added between the prefix and array key names.

Edit this paragraph example
1

<?php $a = ' Original ';
$my _array = Array ("A" => "Cat", "B" => "Dog", "C" => "horse");
Extract ($my _array);
echo "\ $a = $a;
\ $b = $b;
\ $c = $c ";
?>

Output:

$a = Cat;
$b = Dog;
$c = Horse

Edit this paragraph example
2
Use all parameters:

<?php $a = ' Original ';
$my _array = Array ("A" => "Cat", "B" => "Dog", "C" => "horse");
Extract ($my _array, Extr_prefix_same, ' DUP ');
echo "\ $a = $a;
\ $b = $b;
\ $c = $c;
\ $dup _a = $dup _a;
";
?>

This article links http://www.cxybl.com/html/wlbc/Php/20130626/38825.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.