PHP extract array split into multiple variables

Source: Internet
Author: User
    1. $size = "Old Size"; Note the value of the last size variable.
    2. $a = Array (
    3. "Color" = "Red",
    4. "Size" = "XXL",
    5. "Price" = "53");
    6. Extract ($a);
    7. echo "color = $color
      ";
    8. echo "size = $size
      ";
    9. echo "Price = $price
      ";
    10. ?>
Copy Code

Output: color = red Size = XXL Price = 53

The above example finds that the value of $size is XXL, not the previous "old size", which means that the original variable is overwritten by default when the key in the array conflicts with an existing variable.

The following two optional arguments for the Extract function continue to be introduced.

The second parameter, $extract_type, is used to control when a conflict occurs, with the possible values:

    1. $a = Array (
    2. "Color" = "Red",
    3. "Size" = "XXL",
    4. "Price" = "53");
    5. Extract ($a, Extr_prefix_all, "SC");
    6. echo "color = $SC _color
      ";
    7. echo "size = $SC _size
      ";
    8. echo "Price = $SC _price
      ";
    9. Extract ($a, extr_refs);
    10. $color = "green";
    11. echo $a [' color ']; View the values of the original array
    12. ?>
Copy Code

Output: color = red Size = XXL Price = $ green

  • 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.