简体   繁体   中英

convert array to associative array

I have an array like this:

Array
(
    [0] => name
    [1] => john
    [2] => last
    [3] => doe
    [4] => company
    [5] => sony
)

I need to convert to this:

Array
(
    [name] => john
    [last] => doe
    [company] => sony
)

Any ideas?

for ($i = 0; $i < count($myArray); $i += 2)
    $newArray[ $myArray[$i] ] = $myArray[$i+1];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM