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

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

php printf adds number to output

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

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

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...