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
Post a Comment