3v4l.org

run code in 300+ PHP versions simultaneously
<?php function flatten_array($array, $preserve_keys = 0, &$out = array()) { # Flatten a multidimensional array to one dimension, optionally preserving keys. # # $array - the array to flatten # $preserve_keys - 0 (default) to not preserve keys, 1 to preserve string keys only, 2 to preserve all keys # $out - internal use argument for recursion foreach($array as $key => $child) if(is_array($child)) $out = flatten_array($child, $preserve_keys, $out); elseif($preserve_keys + is_string($key) > 1) $out[$key] = $child; else $out[] = $child; return $out; } $array = array( 'first' => 1, 'second' => 2, 'query' => array( 'id' => 314, 'descripcion' => 'Test', 'files' => array( array( 'name' => 'Readme.txt', 'path' => '/tmp/43143431431343', ), array( 'name' => 'Picture.jpg', 'path' => '/tmp/98794894594655', ), ), ), 'last' => 99, ); echo "Original:\n"; var_export($array); echo "\n\nFlat:\n"; var_export( flatten_array($array, 1) );
Output for git.master_jit, git.master, rfc.property-hooks
Original: array ( 'first' => 1, 'second' => 2, 'query' => array ( 'id' => 314, 'descripcion' => 'Test', 'files' => array ( 0 => array ( 'name' => 'Readme.txt', 'path' => '/tmp/43143431431343', ), 1 => array ( 'name' => 'Picture.jpg', 'path' => '/tmp/98794894594655', ), ), ), 'last' => 99, ) Flat: array ( 'first' => 1, 'second' => 2, 'id' => 314, 'descripcion' => 'Test', 'name' => 'Picture.jpg', 'path' => '/tmp/98794894594655', 'last' => 99, )

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