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

Ask about a PHP problem here.
Post Reply
dareskog
Posts: 12
Joined: Sat Jan 21, 2012 2:49 am

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

Post by dareskog »

I need the output of this to be:

This is another
This is awesome

[syntax=php]<?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;
}

?>[/syntax]

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 =]
dareskog
Posts: 12
Joined: Sat Jan 21, 2012 2:49 am

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

Post by dareskog »

My bad...
I had placed " " around the variables within the $user_selection array

Solved!
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

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

Post by jacek »

[syntax=php]$user_selection = array ("$variable_one", "$variable_three");[/syntax]
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 !
Image
Post Reply