php printf 在输出中添加数字 [英] php printf adds number to output

查看:44
本文介绍了php printf 在输出中添加数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 printf 格式化一些输出,但由于某种原因它在每个项目后输出一个数字.关于为什么会这样以及如何修复它的任何想法?

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);
}

输出

Mo: 09:30-19:0019 Di: 09:30-19:0019 So: geschlossen19

谢谢

推荐答案

不就是因为你在 echoing printf 吗?

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

这篇关于php printf 在输出中添加数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆