3v4l.org

run code in 300+ PHP versions simultaneously
<?php function combineColumns(array $row, $separator) // {{{ { $combined = array(); foreach ($row as $key => $value) { if (false !== strpos($key, $separator)) { $parts = explode($separator, $key); $pkey = array_pop($parts); $ptr = &$combined; while (null !== ($part = array_shift($parts))) { if (!isset($ptr[$part]) || !is_array($ptr[$part])) { $ptr[$part] = array(); } $ptr = &$ptr[$part]; } $ptr[$pkey] = $value; unset($ptr); } else { $combined[$key] = $value; } } return $combined; } print_r(combineColumns(array( 'A' => 1, 'B_C' => 2, 'B_D_A' => 3, 'D_K_F' => 4, ), '_'));
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [A] => 1 [B] => Array ( [C] => 2 [D] => Array ( [A] => 3 ) ) [D] => Array ( [K] => Array ( [F] => 4 ) ) )

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:
34.12 ms | 402 KiB | 8 Q