3v4l.org

run code in 300+ PHP versions simultaneously
<?php function terminal_table($col1, $col2, $max_num_spaces_between_columns) { $num_spaces = $max_num_spaces_between_columns - mb_strlen($col1); if ($num_spaces <= 0) $num_spaces = 1; // Always at least 1 space. return $col1 . str_repeat(' ', $num_spaces) . $col2; } echo terminal_table('Cats', '1', 32) . "\n"; echo terminal_table('Dogs', '2', 32) . "\n"; echo terminal_table('Rabbits', '999', 32) . "\n"; echo terminal_table('Horses', '16', 32) . "\n"; echo terminal_table('Cows', '64', 32) . "\n"; echo terminal_table('Mice', '5', 32) . "\n"; echo terminal_table('Pigs', '16', 32) . "\n"; function tabify($col1, $col2, $numTabs) { $tabs = ''; for ($x = 0; $x < $numTabs; $x ++) { $tabs .= "\t"; } return $col1 . $tabs . $col2; } echo tabify('Cats', '1', 3) . "\n"; echo tabify('Dogs', '2', 3) . "\n"; echo tabify('Rabbits', '999', 3) . "\n"; echo tabify('Horses', '16', 3) . "\n"; echo tabify('Cows', '64', 3) . "\n"; echo tabify('Mice', '5', 3) . "\n"; echo tabify('Pigs', '16', 3) . "\n";

preferences:
62.13 ms | 402 KiB | 5 Q