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";
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Cats 1 Dogs 2 Rabbits 999 Horses 16 Cows 64 Mice 5 Pigs 16 Cats 1 Dogs 2 Rabbits 999 Horses 16 Cows 64 Mice 5 Pigs 16

preferences:
166.4 ms | 404 KiB | 182 Q