3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ ["relation" => "OR"], ["color" => 'green'], ["color" => 'yellow'], ["relation" => "AND"], ["color" => 'black'], ["color" => 'orange'], ["relation" => "OR"], ["color" => 'blue'], ["color" => 'violet'], ]; $ref = []; $result = &$ref; foreach ($input as $row) { if (key($row) === 'relation') { if ($ref) { // not the first relation encountered $ref = &$ref[]; // set $ref to point to new deeper subarray } $ref = $row; // push relation } else { $ref[] = $row; // push color into reference } } var_export($result);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 'relation' => 'OR', 0 => array ( 'color' => 'green', ), 1 => array ( 'color' => 'yellow', ), 2 => array ( 'relation' => 'AND', 0 => array ( 'color' => 'black', ), 1 => array ( 'color' => 'orange', ), 2 => array ( 'relation' => 'OR', 0 => array ( 'color' => 'blue', ), 1 => array ( 'color' => 'violet', ), ), ), )

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:
25.75 ms | 406 KiB | 5 Q