Split the PHPextract array into multiple variables.
- $ Size = "old size"; // pay attention to the value of the last size variable.
- $ A = array (
- "Color" => "red ",
- "Size" => "XXL ",
- "Price" => "53 ");
- Extract ($ );
- Echo "color = $ color
";
- Echo "size = $ size
";
- Echo "price = $ price
";
- ?>
-
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:
- $ A = array (
- "Color" => "red ",
- "Size" => "XXL ",
- "Price" => "53 ");
- Extract ($ a, EXTR_PREFIX_ALL, "SC ");
- Echo "color = $ SC _color
";
- Echo "size = $ SC _size
";
- Echo "price = $ SC _price
";
- Extract ($ a, EXTR_REFS );
- $ Color = "green ";
- Echo $ a ['color']; // view the value of the original array
- ?>
Output result: color = red size = XXL price = 53 green |