Introduction to PHP associated array _ PHP Tutorial

Source: Internet
Author: User
Introduction to PHP associated array. Functions make our code very simple. recently I have read a lot of PHP-related knowledge. here I will introduce you to PHP-related array-related knowledge. Description of international extract (array $ var function can make our code very simple. recently I have read a lot of PHP-related knowledge. here I will introduce you to PHP-related array-related knowledge. Description: The International extract object (array $ var_array [Abstract $ extract_type = EXTR_OVERWRITE [, string $ prefix]) imports the variable array to the current symbol table. Check every key to see if it has a valid variable name.

It also checks the collision with the existing variable symbol table, PHP associated array. This function uses the key as the variable name and value as the variable value. For each key/value pair, a variable is created in the current symbol table, but extract_type and prefix parameters are required. You must use an associated array. a numeric index array will not produce results unless you use EXTR_PREFIX_ALL or EXTR_PREFIX_INVALID.

Invalid mode/number keys and collisions are handled by extract_type. It can be one of the following values:
◆ EXTR_OVERWRITE overwrites existing variables if there is a collision.
◆ If EXTR_SKIP has a collision, do not overwrite the existing variable.
◆ EXTR_PREFIX_SAME if there is a collision, the prefix of the variable name prefix.
◆ Prefix of EXTR_PREFIX_ALL: prefix of all variable names.
◆ EXTR_PREFIX_INVALID is only the prefix of variable names with invalid/numeric prefixes.
◆ EXTR_IF_EXISTS only overwrites the variable. if it already exists in the current symbol table, otherwise, nothing is done. This is useful for defining valid variables in the list, and then extract only has the variables you have defined in the $ _ REQUEST array.
◆ EXTR_PREFIX_IF_EXISTS only creates prefix variable names. if the same variables are not prefixed, they exist in the current symbol table.
◆ EXTR_REFSextract variable reference. This actually means that the value import still references the value of the variable, var_array parameter. You can use this flag, OR 'ing's extract_type, either by yourself OR in combination with any other flag.

If extract_type is not specified, this is assumed EXTR_OVERWRITE. Note that only the prefix extract_type is EXTR_PREFIX_SAME, EXTR_PREFIX_ALL, EXTR_PREFIX_INVALID or EXTR_PREFIX_IF_EXISTS. If the prefix result is a valid variable name, it is not imported to the symbol table. Prefix automatically disconnects from an array. Returns some variables that are successfully imported to the symbol table. Version 4.3.0 EXTR_REFS is added. 4.2.0 EXTR_IF_EXISTS and EXTR_PREFIX_IF_EXISTS are added. 4.0.5 this function now returns some variables. EXTR_PREFIX_INVALID is added. EXTR_PREFIX_ALL includes numeric variables and.

PHP associated array instance

Example: extract ()

One possible use of extract () is to import to the symbol table variable containing the associated array and return wddx_deserialize ().

 
 
  1. php
  2. /* Suppose that $var_array is an array returned from
  3. wddx_deserialize */
  4. $size = "large";
  5. $var_array = array("color" => "blue",
  6. "size" => "medium",
  7. "shape" => "sphere");
  8. extract($var_array, EXTR_PREFIX_SAME, "wddx");
  9. echo "$color, $size, $shape, $wddx_sizen";
  10. ?>

Bytes. Description of international extract objects (array $ var...

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.