change associated array to indexed array

sometimes i want to change this form of array

array('position'=> array('data1', 'data2'..)
'year' => array('year1', 'year2'..)
)

to this

array(0 => array('position'=> 'data1',
'year' => 'year1'),
1 => array('position' => 'data2',
'year' => 'year2')

here is how i do it.

function array_group($data)
{
$result = array();
foreach($data as $key=>$rows)
foreach($rows as $i=>$value)
$result[$i][$key] = $value;

return $result;
}

Advertisements

Published by

paragasu

Different. In a good way

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s