Reputation: 1300
I wanted to format some output using printf, but it outputs a number after each item for some reason. Any ideas as to why this is and how it could be fixed?
$array = array("Mo" => "09:30-19:00",
"Di" => "09:30-19:00",
"So" => "geschlossen");
foreach( $array as $key => $value ){
echo printf("%3s:%15s", $key, $value);
}
output
Mo: 09:30-19:0019 Di: 09:30-19:0019 So: geschlossen19
Thank you
Upvotes: 3
Views: 584
Reputation: 10523
Isn't it just because you're echo
ing a printf
?
<?php
$array = array("Mo" => "09:30-19:00",
"Di" => "09:30-19:00",
"So" => "geschlossen");
foreach( $array as $key => $value ){
printf("%3s:%15s", $key, $value);
}
Mo: 09:30-19:00 Di: 09:30-19:00 So: geschlossen
Upvotes: 5
Reputation: 1230
Is there any particular reason you are using echo printf(...)
rather than just echo
?
If not, then using this returns correctly (without the 19 being appended):
$array = array("Mo" => "09:30-19:00",
"Di" => "09:30-19:00",
"So" => "geschlossen");
foreach( $array as $key => $value ){
echo "$key:$value";
}
Upvotes: 0