In PHP, we can use the Extract or compact function to convert an array to a variable, so let's use these two functions to share two instances.
Compact multiple variable-to-array
The code is as follows |
Copy Code |
Multiple variable to array $name = ' Phpff '; $email = ' phpff@phpff.com '; $info =compact (' name ', ' email ');//Pass variable name Print_r ($info); /* Array ( [Name] = Phpff [Email] = phpff@phpff.com ) */ ?> |
Extract array to multiple variables
The code is as follows |
Copy Code |
Array to multiple variables $capitalcities [' England '] = ' London '; $capitalcities [' Scotland '] = ' Edinburgh '; $capitalcities [' Wales '] = ' Cardiff '; Extract ($capitalcities);//Convert to three variables England,scotland,wales Print $Wales;//cardiff ?> |
Cases
The code is as follows |
Copy Code |
$my _array = Array ("A" = "Cat", "b" = "Dog", "c" = "Horse"); Extract ($my _array); echo "$a = $a; $b = $b; $c = $c "; ?> |
Results
$a = Cat; $b = Dog; $c = Horse
http://www.bkjia.com/PHPjc/632672.html www.bkjia.com true http://www.bkjia.com/PHPjc/632672.html techarticle in PHP, we can use the Extract or compact function to convert an array to a variable, so let's use these two functions to share two instances. Compact multiple variable -to-array ...