3v4l.org

run code in 500+ PHP versions simultaneously
<?php function interleave($students, $lessons) { $numStudents = count($students); $numLessons = count($lessons); if ( $numLessons >= $numStudents ) { $studentSliceSize = 1; $lessonSliceSize = intdiv($numLessons, $numStudents); } else { $studentSliceSize = intdiv($numStudents, $numLessons); $lessonSliceSize = 1; } $combinedArray = []; $nextStudent = 0; $nextLesson = 0; while ( $nextStudent < $numStudents || $nextLesson < $numLessons ) { $studentSlice = array_slice($students, $nextStudent, $studentSliceSize); array_push($combinedArray, ...$studentSlice); $nextStudent += $studentSliceSize; $lessonSlice = array_slice($lessons, $nextLesson, $lessonSliceSize); array_push($combinedArray, ...$lessonSlice); $nextLesson += $lessonSliceSize; } return $combinedArray; } var_dump(interleave(['John'], ['Maths'])); var_dump(interleave(['John'], ['Maths', 'Science'])); var_dump(interleave(['John', 'Mary'], ['Maths', 'Science'])); var_dump(interleave(['John', 'Mary', 'Sarah'], ['Maths', 'Science'])); var_dump(interleave(['John', 'Mary', 'Sarah', 'David'], ['Maths', 'Science'])); var_dump(interleave(['John', 'Mary', 'Sarah', 'David', 'Tim'], ['Maths', 'Science'])); var_dump(interleave(['John', 'Mary'], ['Maths', 'Science', 'Music'])); var_dump(interleave(['John', 'Mary'], ['Maths', 'Science', 'Music', 'English']));
Output for rfc.property-hooks, git.master, git.master_jit
array(2) { [0]=> string(4) "John" [1]=> string(5) "Maths" } array(3) { [0]=> string(4) "John" [1]=> string(5) "Maths" [2]=> string(7) "Science" } array(4) { [0]=> string(4) "John" [1]=> string(5) "Maths" [2]=> string(4) "Mary" [3]=> string(7) "Science" } array(5) { [0]=> string(4) "John" [1]=> string(5) "Maths" [2]=> string(4) "Mary" [3]=> string(7) "Science" [4]=> string(5) "Sarah" } array(6) { [0]=> string(4) "John" [1]=> string(4) "Mary" [2]=> string(5) "Maths" [3]=> string(5) "Sarah" [4]=> string(5) "David" [5]=> string(7) "Science" } array(7) { [0]=> string(4) "John" [1]=> string(4) "Mary" [2]=> string(5) "Maths" [3]=> string(5) "Sarah" [4]=> string(5) "David" [5]=> string(7) "Science" [6]=> string(3) "Tim" } array(5) { [0]=> string(4) "John" [1]=> string(5) "Maths" [2]=> string(4) "Mary" [3]=> string(7) "Science" [4]=> string(5) "Music" } array(6) { [0]=> string(4) "John" [1]=> string(5) "Maths" [2]=> string(7) "Science" [3]=> string(4) "Mary" [4]=> string(5) "Music" [5]=> string(7) "English" }

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:
40.21 ms | 1478 KiB | 4 Q