<?php
$array = Array(
'2' => '50',
'3' => '60',
'4' => '12',
'5' => '23',
'12' => '43',
'13' => '43',
'28' => '54',
'29' => '34',
'30' => '54',
'31' => '23',
'32' => '43',
'53' => '23',
"90" => "43",
"91" => "43",
"92" => "43",
"93" => "54",
"94" => "89",
"95" => "12",
"96" => "11",
);
echo '<pre>';
print_r($array);
echo '</pre>';
?>
<?php
$array = Array(
'2' => '50',
'3' => '60',
'4' => '12',
'5' => '23',
'12' => '43',
'13' => '43',
'28' => '54',
'29' => '34',
'30' => '54',
'31' => '23',
'32' => '43',
'53' => '23',
"90" => "43",
"91" => "43",
"92" => "43",
"93" => "54",
"94" => "89",
"95" => "12",
"96" => "11",
);
$array2 = array();
$k = key($array);
$i = 0;
$array2[$i][$k] = current($array);
unset($array[$k]);
foreach($array as $key => $value){
if(($key - $k) == 1){
$array2[$i][$key] = $value;
}else{
if(count($array2[$i]) < 4){
unset($array2[$i]);
$i--;
}
$i++;
$array2[$i][$key] = $value;
}
$k = $key;
}
var_dump($array2);
<?php
$arr = Array(
'2' => '50',
'3' => '60',
'4' => '12',
'5' => '23',
'12' => '43',
'13' => '43',
'28' => '54',
'29' => '34',
'30' => '54',
'31' => '23',
'32' => '43',
'53' => '23',
"90" => "43",
"91" => "43",
"92" => "43",
"93" => "54",
"94" => "89",
"95" => "12",
"96" => "11",
"103" => "154",
"104" => "154"
);
function terurut($array){
$array2 = array();
$k = key($array);
$i = 0;
$array2[$i][$k] = current($array);
unset($array[$k]);
foreach($array as $key => $value){
if(($key - $k) == 1){
$array2[$i][$key] = $value;
}else{
if(count($array2[$i]) < 4){
unset($array2[$i]);
$i--;
}
$i++;
$array2[$i][$key] = $value;
}
$k = $key;
}
return $array2;
}
$hasil_terurut = terurut($arr);
echo "<pre>";
print_r($hasil_terurut);
echo "</pre>";
?>
<?php
$array = Array(
'2' => '50',
'3' => '60',
'4' => '12',
'5' => '23',
'12' => '43',
'13' => '43',
'28' => '54',
'29' => '34',
'30' => '54',
'31' => '23',
'32' => '43',
'53' => '23',
"90" => "43",
"91" => "43",
"92" => "43",
"93" => "54",
"94" => "89",
"95" => "12",
"96" => "11",
"103" => "154",
"104" => "154",
);
$array2 = array();
$k = key($array);
$i = 0;
$array2[$i][$k] = current($array);
unset($array[$k]);
foreach($array as $key => $value){
if(($key - $k) == 1){
$array2[$i][$key] = $value;
}else{
if(count($array2[$i]) < 4){
unset($array2[$i]);
$i--;
}
$i++;
$array2[$i][$key] = $value;
}
$k = $key;
}
if(count(end($array2)) < 4){
array_pop($array2);
}
var_dump($array2);