3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = ['a_a' => '2', 'a_b' => '333', 'c_c' => '123']; function flattenToMultiDimensional(array $array, $delimiter = '.') { $result = []; foreach ($array as $notations => $value) { // extract keys $keys = explode($delimiter, $notations); // reverse keys for assignments $keys = array_reverse($keys); // set initial value $lastVal = $value; foreach ($keys as $key) { // wrap value with key over each iteration $lastVal = [ $key => $lastVal ]; } // merge result $result = array_merge_recursive($result, $lastVal); } return $result; } var_export(flattenToMultiDimensional($array, '_'));
Output for git.master, git.master_jit, rfc.property-hooks
array ( 'a' => array ( 'a' => '2', 'b' => '333', ), 'c' => array ( 'c' => '123', ), )

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:
65.04 ms | 1255 KiB | 4 Q