Consider:
array(0 => array('id'=>'1', 'element1'=>'value1', 'element2'=>'value2'));
Now consider:
array(0 => ( array('id'=>'1')),
1 => ( array('element1'=>'value1')),
2 => ( array('element2'=>'value2'))
);
What would be the best way to traverse the first array to create the second array above?
asked Apr 28, 2014 at 13:20
1 Answer 1
Without any further qualifications as to the logic that needs to be applied, this will do:
$array2 = array_chunk($array1[0], 1, true);
answered Apr 28, 2014 at 13:22
-
Yes - I've tested it and that works perfectly. Thank you. I will accept the answer when I am able (SO tells me I can accept an answer in 7 minutes!)Steve Cooke– Steve Cooke04/28/2014 13:29:17Commented Apr 28, 2014 at 13:29
lang-php