Advertisement
cdsatrian

array sort extended

Jun 7th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.62 KB | None | 0 0
  1. <?php
  2. $arr= array("2" =>"ayam", "3" =>"ikan","4" =>"katak", "5" =>"burung", "8" => "itik", "9" => "rusa","10" => "sapi", "11" => "kerbau", "13" => "kancil", "14" => "buaya", "15" => "semut", "17" =>"lebah", "18" => "cacing","19" => "ulat", "20" => "lalat", "21" => "nyamuk", "26" => "kutu");
  3. $min=4;
  4. function sort_grouping($data,$limit){
  5. $n=0;
  6. foreach($data as $k=>$v){
  7. $n=($n==0?$k-1:$n);
  8. if(($k-$n)==1){
  9. $temp_arr[$k]=$v;
  10. }else{
  11. if(count($temp_arr)>=$limit){
  12. $new_arr[]=$temp_arr;
  13. }
  14. unset($temp_arr);
  15. $temp_arr[$k]=$v;
  16. }
  17. $n=$k;
  18. }
  19. return $new_arr;
  20. }
  21. echo "<pre>";
  22. print_r(sort_grouping($arr,4));
  23. echo "</pre>";
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement