函数sprintf()作用是什么解决方案

WBOY
Release: 2016-06-13 11:54:31
Original
896 people have browsed it

函数sprintf()作用是什么
我的PHP手册中sprintf()的说明全是英文,我看不懂。有没有大侠能把该函数的作用(尤其是参数format)详细地说一下?
------解决方案--------------------
是的
%.2f 表示按 2 位小数格式化

整数自然是没有小数的

------解决方案--------------------
这是 php 特有的一个方式,使用的并不多(他给的例子已经说得很清楚了)
这是正常的写法

$a = 123;<br />$b = 1111;<br />$txt = sprintf("%.2f  %u",$a, $b);<br />echo $txt;
Copy after login
123.00 1111
当写作
$txt = sprintf("%2\$.2f  %1\$u",$a, $b);<br />echo $txt;<br />
Copy after login
1111.00  123
可以看到对应位置的值发生了变化
于是可知:数字表示的是参数的序号

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!