3v4l.org

run code in 300+ PHP versions simultaneously
<?php $inputArray = array( array( array( 'value31', 'value32' ), array( 'value33', 'value34' ), 'value21' ), 'value11' ); function convertArray($inputArray) { if(!checkIfAllArraysExceptLast($inputArray)) return $inputArray; $value = array_pop($inputArray); $result = []; foreach($inputArray as $k => $v){ $result[$k] = is_array($v) ? convertArray($v) : $v; } return [ $value => $result]; } function checkIfAllArraysExceptLast($array){ $v = array_pop($array); return !is_array($v) && count(array_filter($array, fn($v) => is_array($v))) == count($array); } print_r(convertArray($inputArray));
Output for git.master_jit, git.master, rfc.property-hooks
Array ( [value11] => Array ( [0] => Array ( [value21] => Array ( [0] => Array ( [0] => value31 [1] => value32 ) [1] => Array ( [0] => value33 [1] => value34 ) ) ) ) )

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:
22.84 ms | 407 KiB | 5 Q