php - Convert an array of 2-element arrays to an array making 2 elements as key => value -
is possible convert following array using php built-in functions array contain value of id
key , value of label
associated value? if not what's efficient way?
thanks.
input array:
array ( [0] => array ( [id] => 2 [label] => mtd-589 ) [1] => array ( [id] => 3 [label] => mtd-789 ) )
output array:
array ( [2] => mtd-589, [3] => mtd-789, )
introducing array_column (still in php 5.5 beta).
$new_array = array_column($your_array 'label', 'id');
output:
array ( [2] => mtd-589, [3] => mtd-789, )
using array_walk.
array_walk($array, function($a) use (&$return) { $return[$a['id']] = $a['label']; }); print_r($return);