Reputation: 1961
I have array in following format. I want to convert it into another format like below.
Array
(
[b2] => 2
[b3] => 8
[b4] => 2
[b5] => 4
)
Is it possible key is converted into PHP variables and its value automatically assigned to variables? Is it possible?
$b2 = 2;
$b3 = 8;
$b4 = 2;
$b5 = 4;
Upvotes: 0
Views: 245
Reputation: 22675
You're looking for the extract() function. You pass in the array you want to extract into the current scope, and that's it. Mind though that you should be very careful when you use this function; for safety, pass EXTR_SKIP
in as the second argument to prevent overwriting existing variables, after all you wouldn't want the likes of $_SESSION
or $_SERVER
throttled by an array with malicious data...
Upvotes: 0