Insert variable content into list()

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

taquin21
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Sep 12, 2012 8:36 am

Insert variable content into list()

Postby taquin21 » Wed Sep 12, 2012 8:42 am

Hi,

I need to insert variable content (which is a list of variables name) into list(). In the example below, I want the 3rd line to be like this: list($color, $power, $item1,$item2) = $info;

HOw can I do this?

Code: Select all

$info = array('brown', 'caffeine', 'hockey', 'football');

$sport = '$item1,$item2';

list($color, $power, $sport) = $info;


Thanks for your help,

Luc

us2rn4m2
New php-forum User
New php-forum User
Posts: 17
Joined: Thu Aug 09, 2012 1:28 pm

Re: Insert variable content into list()

Postby us2rn4m2 » Fri Sep 14, 2012 12:59 pm

Hi,

Code: Select all

$info  = array('brown', 'caffeine', 'hockey', 'football');
$sport = array();
                     //hokey   // football 
list($color, $power, $sport[0], $sport[1]) = $info;

echo $color . ' ' . $power . ' ' . $sport[0] . ' ' . $sport[1];

// Result: brown caffeine hockey football


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 3 guests