How to use extract and compact functions in PHP
This article mainly introduces how to use extract and compact functions in PHP. It is very detailed and has a certain reference value. Friends who are interested must finish it!
Extract (import variables from an array into the current symbol table), compact (create an array containing variable names and their values)
A = "Original"; $my_array = array ("a" = > "Cat", "b" = > "Dog", "c" = > "Horse"); extract ($my_array); echo "\ $a = $a;\ $b = $b;\ $c = $c"
Output:
$a = Cat; $b = Dog; $c = Horse
$firstname = "Peter"; $lastname = "Griffin"; $age = "41"; $result = compact ("firstname", "lastname", "age"); print_r ($result)
Output:
Array
(
[firstname] = > Peter
[lastname] = > Griffin
[age] = > 41
)
These are all the contents of the article "how to use extract and compact functions in PHP". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!