Does anyone know why when I execute this :
#!/usr/bin/php
<?php
$eff_theo = array_fill(0, 10, 100);
for ($i = 0; $i < 10; ++$i)
echo printf("%5d", $eff_theo[$i]).' ';
echo PHP_EOL;
?>
I get this :
1005 1005 1005 1005 1005 1005 ...
Does anyone know why when I execute this :
#!/usr/bin/php
<?php
$eff_theo = array_fill(0, 10, 100);
for ($i = 0; $i < 10; ++$i)
echo printf("%5d", $eff_theo[$i]).' ';
echo PHP_EOL;
?>
I get this :
1005 1005 1005 1005 1005 1005 ...
You're mixing echo
and printf
.
printf
returns the length of the formatted string, so your echo
call is printing out '5'.
Try removing the echo
and try it again....