chipz
chipz

Reputation: 806

PHP: How to make new specific formatted array from another array

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

Answers (1)

Ian Atkin
Ian Atkin

Reputation: 6356

$newarr = array_shift($arr)
$newarr = array_flip($newarr)

Or you could combine:

$newarr = array_shift(array_flip($arr))

Upvotes: 1

Related Questions