Split the PHPextract array into multiple variables.

Source: Internet
Author: User
Split the PHPextract array into multiple variables.

  1. $ Size = "old size"; // pay attention to the value of the last size variable.
  2. $ A = array (
  3. "Color" => "red ",
  4. "Size" => "XXL ",
  5. "Price" => "53 ");
  6. Extract ($ );
  7. Echo "color = $ color
    ";
  8. Echo "size = $ size
    ";
  9. Echo "price = $ price
    ";
  10. ?>

Output result: color = red size = XXL price = 53

In the previous example, we found that the value of $ size is XXL, instead of the previous "old size". This indicates that by default, when the key in the array conflicts with an existing variable, the original variable will be overwritten.

Continue to introduce the last two optional parameters of the extract function.

The second parameter $ extract_type is used to control the processing method when a conflict occurs. the possible value is:

  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 value of the original array
  12. ?>

Output result: color = red size = XXL price = 53 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.