3v4l.org

run code in 300+ PHP versions simultaneously
<?php function hydratePath(array $result, ?string $path): array { if (sscanf($path ?? '', '%[^/]/%s', $first, $rest) < 2) { $result[] = $first ?? $path; } else { $result[$first] ??= []; $result[$first] = (__FUNCTION__)($result[$first], $rest); } return $result; } $array = [ 'invoice/products/data/item1', '', null, 'invoice/products/data/item2', 'invoice/products/filename', 'invoice/products/data/item2', 'foo/bar/baz', '', 'aaa/bbb' ]; var_export(array_reduce($array, "hydratePath", []));
Output for git.master, git.master_jit, rfc.property-hooks
array ( 'invoice' => array ( 'products' => array ( 'data' => array ( 0 => 'item1', 1 => 'item2', 2 => 'item2', ), 0 => 'filename', ), ), 0 => '', 1 => NULL, 'foo' => array ( 'bar' => array ( 0 => 'baz', ), ), 2 => '', 'aaa' => array ( 0 => 'bbb', ), )

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