【发布时间】:2010-11-26 01:47:12
【问题描述】:
我正在尝试了解有关 PHP 函数 sprintf() 的更多信息,但 php.net 对我没有多大帮助,因为我仍然感到困惑,为什么要使用它?
看看我下面的例子。
为什么要用这个:
$output = sprintf("Here is the result: %s for this date %s", $result, $date);
当这样做相同并且更容易编写 IMO 时:
$output = 'Here is the result: ' .$result. ' for this date ' .$date;
我错过了什么吗?
【问题讨论】:
-
+1,好问题。我自己很少使用它,所以我有兴趣看到答案。
-
我个人在连接很多东西时使用它。直到那时我才发现它很有用,主要是为了可读性。