Reformulate new array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Reformulate new array

Post by PHPycho »

I had the following array:

Code: Select all

array(
'title_1' => 'some value',
'link_1' => 'some value',
'title_2' => 'some value',
'link_2' => 'some value',
'title_3' => 'some value',
'link_3' => 'some value',
...
)
I want to convert this array as follow:

Code: Select all

array(
    array('title_1' => 'some value',
          'link_1' => 'some value'),
    array('title_2' => 'some value',
          'link_2' => 'some value'),
    array('title_3' => 'some value',
          'link_3' => 'some value'),
...
)
So that i can group items and loop easily.

Thanks
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Reformulate new array

Post by John Cartwright »

Assuming you can just pair each 2 rows together,

Code: Select all

$newarray = array_chunk($oldarray, 2, true);
Post Reply