Page 1 of 1

Extracting a key variable from an array within an array :S

Posted: Mon May 07, 2012 12:55 pm
by dareskog
I need the output of this to be:

This is another
This is awesome
<?php

$variable_one = array ("one"=>"This is one", "two"=>"This is another");
$variable_two = array ("one"=>"This is two", "two"=>"This is working lol");
$variable_three = array ("one"=>"This is three", "two"=>"This is awesome!");

$user_selection = array ("$variable_one", "$variable_three");

foreach($user_selection as $feed){
extract($feed);
echo $two;
}

?>
I think my thought process is right but I get this error:

Warning: extract() [function.extract]: First argument should be an array in /home/a6972369/public_html/test/index.php on line 10

Would anybody be able to help?
Cheers for your time =]

Re: Extracting a key variable from an array within an array

Posted: Mon May 07, 2012 1:31 pm
by dareskog
My bad...
I had placed " " around the variables within the $user_selection array

Solved!

Re: Extracting a key variable from an array within an array

Posted: Mon May 07, 2012 3:38 pm
by jacek
$user_selection = array ("$variable_one", "$variable_three");
No need for the quotes on this line ;)

Also I have never seen extract() actually being used for somethign that makes sense, so good job !