Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert assoc array to variables 2

Status
Not open for further replies.

LaundroMat

Programmer
Dec 2, 2003
67
BE
I'm pretty sure I saw a way to convert an associative array to variables.
This array:
$array = ("one"=>1, "two"=>2);
Can it be converted to two variables, $one and $two, with the values 1 and 2?

I think I'm blind, as I can't find this anywhere in the manual anymore...
 
Use the function extract(), see for more information. Here's the example from the web page (slightly modified):
Code:
<?php
$var_array = array("color" => "blue",
                   "size"  => "medium",
                   "shape" => "sphere");
extract($var_array);

echo "$color, $size, $shape\n";
?>
The above code prints:
Code:
blue, medium, sphere

Ken
 
Thanks the both of you. On my way home I was thinking of the variable variables solution, but then I was sure I saw a function somewhere. And that's extract().

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top