3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ [ "forename" => "Dave", "surname" => "Wood", "dob" => "23/05/1986", "gender" => "Male", ], ]; function outputr(array $input) { // work out the max length for each field $lengths = []; foreach ($input as $row) { foreach ($row as $key => $value) { if (!isset($lengths[$key])) { $lengths[$key] = 0; } $kl = strlen($key); $vl = strlen($value); $ln = ($kl > $vl) ? $kl : $vl; if ($ln > $lengths[$key]) { $lengths[$key] = $ln; } } } // output the table header foreach ($lengths as $key => $length) { echo "+" . str_repeat("-", $length); } echo "+\n"; foreach ($lengths as $key => $length) { $pad = $length - strlen($key); echo "| {$key}"; echo str_repeat(" ", $length); } echo "|\n"; } outputr($input);

preferences:
58.28 ms | 402 KiB | 5 Q