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

Using Android Volley to post an array to PHP -

python - How to add an model instance to a django queryset? -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -