Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $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");
- $min=4;
- function sort_grouping($data,$limit){
- $n=0;
- foreach($data as $k=>$v){
- $n=($n==0?$k-1:$n);
- if(($k-$n)==1){
- $temp_arr[$k]=$v;
- }else{
- if(count($temp_arr)>=$limit){
- $new_arr[]=$temp_arr;
- }
- unset($temp_arr);
- $temp_arr[$k]=$v;
- }
- $n=$k;
- }
- return $new_arr;
- }
- echo "<pre>";
- print_r(sort_grouping($arr,4));
- echo "</pre>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement