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') { // populate current level $ref[] = $row; continue; } if ($ref) { // not the first relation encountered $ref = &$ref[]; } $ref = $row; // store relation } 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:
26.1 ms | 406 KiB | 5 Q