Display php-cli output in columns

I want to output variable-length data in columns in php-cli script

Example:

$pepole = Array( 'Mirco Dellarovere' => 'Artista', 'Nino Pepe' => 'Attore', 'Zoe Yan' => 'Futurista', 'Mino' => 'Elettricista' ); foreach($pepole as $name => $work) { echo "$name\t$work\n"; } 

The output will be

 Mirco Dellarovere Artista Nino Pepe Attore Zoe Yan Futurista Mino Elettricista 

but i want it that way

 Mirco Dellarovere Artista Nino Pepe Attore Zoe Yan Futurista Mino Elettricista 

as?

:) thanks

+7
source share
1 answer

You can pad $name provide a standard number of characters. Just make sure the number of characters (20) is equal to or greater than the length of the longest name:

 echo str_pad( $name, 20 ) . $work . "\n"; 
+13
source

All Articles