Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting an array into the variables in php

I have this array, $display_vars, and I want to split it into separate variables, so each variable's name is the array key, and it's value is the value, so to speak. So if the array was like this:

$display_vars = array(
'title' => 'something',
'header' => 'something else'
);

Then I want to end up with the equivalent of this:

$title = 'something';
$header = 'something else';

Can you think of any way I can possibly do this?

like image 407
sujitrulz Avatar asked Dec 07 '11 17:12

sujitrulz


2 Answers

extract()

Be mindful about overwriting variables of the same name in the current scope. Read up on the second parameter if this is a concern.

like image 58
Jason McCreary Avatar answered Oct 06 '22 04:10

Jason McCreary


Use

extract($display_vars);

http://php.net/manual/en/function.extract.php

like image 39
Mangirdas Skripka Avatar answered Oct 06 '22 05:10

Mangirdas Skripka