3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $cha12 = array(); $cha1_count = 3; $cha2_count = 3; $cha12[0][0] = 3; $cha12[0][1] = 6; $cha12[0][2] = 2; $cha12[1][0] = 4; $cha12[1][1] = 5; $cha12[1][2] = 3; $cha12[2][0] = 2; $cha12[2][1] = 2; $cha12[2][2] = 8; $fcount = 0; $fcount_array = array(); $fc = 0; for($count1=0;$count1<$cha1_count;$count1++){ for($count2=0;$count2<$cha2_count;$count2++){ $fc = ($cha2_count * $count1) + $count2; $fcount_array[$fc] = $cha12[$count1][$count2]; } } asort($fcount_array); print_r($fcount_array); //1 $akf = array_keys($fcount_array); print_r($akf); //2 $acv = array_count_values($fcount_array); print_r($acv); //3 $ak = array_keys($acv); print_r($ak); //4 $ak_count = count($ak); $ak_sum = 0; if($cha1_count <= $cha2_count){ $sum = $ak[$ak_count-1]*$cha1_count; //合計の最大値をとりあえず決めておく for($i=0;$i<$ak_count;$i++){ $ak_sum = $ak_sum + $acv[$ak[i]]; if($ak_sum < $cha1_count){ break; } for($j=0;$j<$ak_sum-$cha1_count+1;$j++){ $c=1; $c1=array(); $c2=array(); $n_sum=$cha12[floor($akf[$j]/$cha1_count)][$akf[$j]%$cha1_count]; $c1[0]=floor($akf[j]/$cha1_count); $c2[0]=$akf[j]%$cha1_count; for($k=$j+1;$k<$ak_sum;$k++){ if($c<$cha1_count){ for($m=0;$m<$c;$m++){ if(floor($akf[$k]/$cha1_count) == $c1[$m] || $akf[$k]%$cha1_count == $c2[$m]){ break; } } $c1[$c]=floor($akf[$k]/$cha1_count); $c2[$c]=$akf[$k]%$cha1_count; $n_sum=$n_sum+$cha12[floor($akf[$k]/$cha1_count)][$akf[$k]%$cha1_count]; $c++; if($c==$cha1_count && $n_sum<$sum){ $sum=$n_sum; } } } } } } ?>
Output for 5.3.0 - 7.1.0
Array ( [6] => 2 [2] => 2 [7] => 2 [0] => 3 [5] => 3 [3] => 4 [4] => 5 [1] => 6 [8] => 8 ) Array ( [0] => 6 [1] => 2 [2] => 7 [3] => 0 [4] => 5 [5] => 3 [6] => 4 [7] => 1 [8] => 8 ) Array ( [2] => 3 [3] => 2 [4] => 1 [5] => 1 [6] => 1 [8] => 1 ) Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 [4] => 6 [5] => 8 ) Notice: Use of undefined constant i - assumed 'i' in /in/hYS9h on line 36 Notice: Undefined index: i in /in/hYS9h on line 36 Notice: Undefined index: in /in/hYS9h on line 36
Output for 4.3.0 - 5.2.17
Array ( [6] => 2 [2] => 2 [7] => 2 [0] => 3 [5] => 3 [3] => 4 [4] => 5 [1] => 6 [8] => 8 ) Array ( [0] => 6 [1] => 2 [2] => 7 [3] => 0 [4] => 5 [5] => 3 [6] => 4 [7] => 1 [8] => 8 ) Array ( [2] => 3 [3] => 2 [4] => 1 [5] => 1 [6] => 1 [8] => 1 ) Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 [4] => 6 [5] => 8 ) Notice: Use of undefined constant i - assumed 'i' in /in/hYS9h on line 36 Notice: Undefined index: i in /in/hYS9h on line 36 Notice: Undefined index: in /in/hYS9h on line 36