php - Is it possible to create an array from existing array by pairing every two values into key and value? -



php - Is it possible to create an array from existing array by pairing every two values into key and value? -

this want do.

i have array.

$arr = array('value1','value2','value3','value4','value5','value6');

is possible pair every 2 values like:

$new_arr = array('value1' => 'value2','value3' => 'value4', 'value5' => 'value6');

in first array, there no keys. values. want pair them..in same order every key => value (the next it..just illustration above)

is possible? badly need it..

assuming array has number of members can do:

for($i=0 ; $i<count($arr)-1 ; $i+=2) { $new_array[$arr[$i]] = $arr[$i+1]; }

where $arr existing array , $new_array new resultant associative array.

working ideone link

php arrays

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -