3v4l.org

run code in 300+ PHP versions simultaneously
<?php $records = [ 'nonsense', 'f', 'h', 1, 2, 3, 4, 'f', 'nonsense', 'h', 1, 2, 'f', 'h', 1, 2, 3, 'f', 'nonsense', 'nonsense', 'nonsense', 'h', 1, 2, 3, 4, 'f', 'h', 1, 'f', 'nonsense' ]; $groups = []; foreach ($records as $record) { if ($record === 'h') { $group = []; } $group[] = $record; if ($record === 'f') { $groups[] = $group; } } var_dump($groups); echo "\n------------------------------------------------------\n\n"; unset($group); $groups = []; foreach ($records as $record) { if ($record === 'h') { $group = []; } if (! isset($group)) { continue; } $group[] = $record; if ($record === 'f') { $groups[] = $group; unset($group); } } var_dump($groups);
Output for git.master, git.master_jit, rfc.property-hooks
array(6) { [0]=> array(2) { [0]=> string(8) "nonsense" [1]=> string(1) "f" } [1]=> array(6) { [0]=> string(1) "h" [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) [5]=> string(1) "f" } [2]=> array(4) { [0]=> string(1) "h" [1]=> int(1) [2]=> int(2) [3]=> string(1) "f" } [3]=> array(5) { [0]=> string(1) "h" [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> string(1) "f" } [4]=> array(6) { [0]=> string(1) "h" [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) [5]=> string(1) "f" } [5]=> array(3) { [0]=> string(1) "h" [1]=> int(1) [2]=> string(1) "f" } } ------------------------------------------------------ array(5) { [0]=> array(6) { [0]=> string(1) "h" [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) [5]=> string(1) "f" } [1]=> array(4) { [0]=> string(1) "h" [1]=> int(1) [2]=> int(2) [3]=> string(1) "f" } [2]=> array(5) { [0]=> string(1) "h" [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> string(1) "f" } [3]=> array(6) { [0]=> string(1) "h" [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) [5]=> string(1) "f" } [4]=> array(3) { [0]=> string(1) "h" [1]=> int(1) [2]=> string(1) "f" } }

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:
60.21 ms | 405 KiB | 8 Q