I have tables with data, I would like to sort it equally according to the type field in order to get such a result:
1 - http://site1.com
2 - http://sitex.com
3 - http://sites.com
4 - http://site2.com
5 - http://site1.com
1 - http://site2.com
2 - http://site3.com
3 - http://site6.com
4 - http://site1.com
5 - http://siteX.com
1 - http://site2.com
2 - http://site8.com
3 - http://site9.com
4 - http://site1.com
5 - http://site1.com
I want to group the mixed data from the array into equal groups according to the value of the type field, from 1-5. I will add that the array does not always have an equal amount of data for type=X. Sometimes there are more and sometimes less
php script:
<?php
$arr = array(
array('type' => 1,'url' => 'http://site1.com'),
array('type' => 4,'url' => 'http://site2.com'),
array('type' => 1,'url' => 'http://site2.com'),
array('type' => 2,'url' => 'http://sitex.com'),
array('type' => 5,'url' => 'http://site1.com'),
array('type' => 1,'url' => 'http://site2.com'),
array('type' => 2,'url' => 'http://site3.com'),
array('type' => 3,'url' => 'http://sites.com'),
array('type' => 4,'url' => 'http://site1.com'),
array('type' => 5,'url' => 'http://siteX.com'),
array('type' => 3,'url' => 'http://site6.com'),
array('type' => 4,'url' => 'http://site1.com'),
array('type' => 5,'url' => 'http://site1.com'),
array('type' => 2,'url' => 'http://site8.com'),
array('type' => 3,'url' => 'http://site9.com'),
);
foreach ($arr as $a){
echo $a['type'].' - '.$a['url'].'<br>';
}
/*-- result
1 - http://site1.com
4 - http://site2.com
1 - http://site2.com
2 - http://sitex.com
5 - http://site1.com
1 - http://site2.com
2 - http://site3.com
3 - http://sites.com
4 - http://site1.com
5 - http://siteX.com
3 - http://site6.com
4 - http://site1.com
5 - http://site1.com
2 - http://site8.com
3 - http://site9.com
--*/
?>
Do you have any idea how I can get such a result?