About PHP associative array related knowledge introduction _php tutorial

Source: Internet
Author: User
function can make our code very simple, recently read a lot of PHP-related knowledge, here to introduce you to the PHP associative array related knowledge. Description International Extract (array $ var_array [abstract $ extract_type = Extr_overwrite [, string $ prefix]]) import variable array into the current symbol table. Check each key to see if it has a valid variable name.

It also checks collisions with existing variable symbol tables, PHP associative arrays. This function takes the key as the variable name and value as the value of the variable. For each key/value pair, a variable is created in the current symbol table, but the extract_type and prefix parameters are required. You must use an associative array, and a numeric index array will not produce results unless you use Extr_prefix_all or Extr_prefix_invalid.

The way invalid/numeric keys and collisions are treated by extract_type. It can be one of the following values:
Extr_overwrite If there is a collision, overwrite the existing variable.
Extr_skip If there is a collision, do not overwrite the existing variable.
Extr_prefix_same If there is a collision, prefix the name of the variable prefixed.
Prefix of all variable names for the Extr_prefix_all prefix.
Extr_prefix_invalid only prefix invalid/numeric prefix of variable name.
Extr_if_exists only overrides the variable if it already exists in the current symbol table, otherwise, nothing is done. It is useful to define the list of valid variables, and then extract only those variables you define the $ _request array.
Extr_prefix_if_exists only creates a prefix variable name if the same variable as the non-prefixed version exists in the current symbol table.
Reference to the Extr_refsextract variable. This actually means that the import of values still refers to the value of the variable, the Var_array parameter. You can use this logo on your own or in conjunction with any other logo or ' ing ' extract_type.

If Extract_type is not specified, this is assumed to be extr_overwrite. Please note that only the prefix is required if Extract_type is Extr_prefix_same, Extr_prefix_all, Extr_prefix_invalid or extr_prefix_if_exists. If the prefix result is not a valid variable name, this is not imported into the symbol table. A prominent feature of the prefix auto-detachment array key. Returns some variables that were successfully imported into the symbol table. Version Description 4.3.0 extr_refs increased. 4.2.0 Extr_if_exists and Extr_prefix_if_exists were added. 4.0.5 This feature now returns some variable extract. Extr_prefix_invalid increased. Extr_prefix_all includes numeric variables as well.

PHP Associative Array instances

Example: Example of a extract object ()

One possible use for extract () is to import into a symbol table variable that contains an associative array that returns Wddx_deserialize ().

 
 
  1. php
  2. /* Suppose that $var _array are 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. ?>

http://www.bkjia.com/PHPjc/446488.html www.bkjia.com true http://www.bkjia.com/PHPjc/446488.html techarticle function can make our code very simple, recently read a lot of PHP-related knowledge, here to introduce you to the PHP associative array related knowledge. Description International Extract (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.