1

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

4

Without any further qualifications as to the logic that needs to be applied, this will do:

$array2 = array_chunk($array1[0], 1, true);

See http://php.net/array_chunk

answered Apr 28, 2014 at 13:22
1
  • 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!) Commented Apr 28, 2014 at 13:29

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.