This article illustrates the method of converting PHP variables and arrays into one another. Share to everyone for your reference, specific as follows:
In PHP, the array and the variable convert to each other we can use the Extract or compact function, here to give you an analysis of the use of these two functions.
Compact multiple variable Array
<?php
//Multiple variable-turn array
$name = ' jb51 ';
$email = ' jb51@jb51.net ';
$info =compact (' name ', ' email ');//pass variable name
print_r ($info);
/* Array
(
[name] => jb51
[email] => jb51@jb51.net
)
* * *
?>
Extract array to multiple variables
<?php
//array to turn multiple variables
$capitalcities [' England '] = ' London ';
$capitalcities [' Scotland '] = ' Edinburgh ';
$capitalcities [' Wales '] = ' Cardiff ';
Extract ($capitalcities)//converted into three variables england,scotland,wales
print $Wales;//cardiff
?>
Cases:
<?php
$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
More about PHP Interested readers can view the site topics: "PHP common functions and Skills summary", "PHP Array" Operation Techniques Encyclopedia, "PHP string (String) Usage summary", "PHP error and Exception handling method summary", " Introduction to PHP Basic Grammar, "Introduction to PHP object-oriented Programming", "PHP+MYSQL Database Operations Introduction Tutorial" and "PHP Common database Operation tips Summary"
I hope this article will help you with the PHP program design.