Reputation: 806
I have an array like this:
$arr = array(
array(
'service' => 'super speed',
'price' => 2000),
array(
'service' => 'regular',
'price' => 1500
)
);
How can i make a new array from that array that use the first element to be the array key:
$newarr = array(
'super speed' => 2000,
'regular' => 1500
);
Thank you for your help.
Upvotes: 1
Views: 45
Reputation: 6356
$newarr = array_shift($arr)
$newarr = array_flip($newarr)
Or you could combine:
$newarr = array_shift(array_flip($arr))
Upvotes: 1