3v4l.org

run code in 300+ PHP versions simultaneously
<?php $aUserFiles = [ 0 => [ 'file' => 'file 1', 'semesters' => [ 3 ] ], 1 => [ 'file' => 'file 2', 'semesters' => [ 3,4 ] ], 2 => [ 'file' => 'file 3', 'semesters' => [ 1,2 ] ], 3 => [ 'file' => 'file 4', 'semesters' => [ 3,4,5,6 ] ] ]; $requiredSemesters = 3; $indicators = []; $result = []; foreach ($aUserFiles as $key => $file) { $first = $file['semesters'][0]; $last = $file['semesters'][count($file['semesters']) - 1]; $filesInRangeCount = count(array_intersect($file['semesters'], range(1, $requiredSemesters))); if (!isset($indicators[$first]) || $indicators[$first]['range'] < $filesInRangeCount) { $indicators[$first] = ["key" => $key, "max" => $last, "range" => $filesInRangeCount]; } } ksort($indicators); $result = []; $max = 0; foreach ($indicators as $indicator) { if ($max >= $requiredSemesters) { break; } $result[] = $aUserFiles[$indicator['key']]; $max = $indicator["max"]; } print_r($result);
Output for git.master_jit, git.master, rfc.property-hooks
Array ( [0] => Array ( [file] => file 3 [semesters] => Array ( [0] => 1 [1] => 2 ) ) [1] => Array ( [file] => file 1 [semesters] => Array ( [0] => 3 ) ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
53.85 ms | 1677 KiB | 4 Q