Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
410 views
Welcome To Ask or Share your Answers For Others

1 Answer

Isn't it just because you're echoing a printf?

http://codepad.org/1KtxR9JF

<?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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...