3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr =Array( 0 => Array ( 0 => "string", 1 => 1, "return" => true ), "two" => Array ( 0 => "2017-10-09", 1 => 248.38, "return" => false ), 3 => -123.4, 4 => array( 0 => array( 0 => "foo", 1 => array( 0 => "bar" ) ) ) ); printArray($arr // Input array for output , "array(" // type of output "array()" or "[]" , 1 // start padding multiplied with 4. 1 = 4 spaces indenting at start. , false // is input a subarray. Always false when you call the function. Only function itself should change this ); function printArray($arr, $output, $pad, $subarray){ // If it's a subarray don't indent "array" text if($subarray){ echo str_pad("", 0, " ") . $output ."\n"; }else{ echo str_pad("", $pad*4, " ") . $output ."\n"; } $i=1; foreach($arr as $key => $item){ if(is_array($item)){ echo str_pad("", ($pad+1)*4, " "); // add "" to key if it's associative if(is_string($key)){ echo "\"" . $key. "\" => "; }else{ echo $key . " => "; } // recrusive run printArray with padding +1 (more indenting) printArray($item, $output, $pad+1, true); }else{ echo str_pad("", ($pad+1)*4, " "); // add "" to key if it's associative if(is_string($key)){ echo "\"" . $key. "\""; }else{ echo $key; } // echo item with "" if it's string, or as bool or else as numeric (float/int) if(is_string($item)){ echo " => \"". $item ."\""; }else if(is_bool($item)){ $bool = var_export($item,true); echo " => ". $bool; }else{ echo " => ". $item; } // if it's the last item, don't add comma to end of array if($i == count($arr)){ echo "\n"; }else{ echo ",\n"; } $i++; } } // add correct closing bracket if($output == "["){ echo str_pad("", $pad*4, " ") . "]"; }else{ echo str_pad("", $pad*4, " ") . ")"; } // if it's the very last item add a ; instead of , if($pad == 1){ echo ";\n"; }else{ if($i == count($arr)){ echo "\n"; }else{ echo ",\n"; } } }
Output for git.master, git.master_jit, rfc.property-hooks
array( 0 => array( 0 => "string", 1 => 1, "return" => true ), "two" => array( 0 => "2017-10-09", 1 => 248.38, "return" => false ), 3 => -123.4, 4 => array( 0 => array( 0 => "foo", 1 => array( 0 => "bar" ), ) ) );

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