首先%s和%d的概念应该很清楚了。但有个缺点就是变量的顺序(the order of the arguments in the code)必须和$format中所使用的代号的顺序(the order of the place holders in the format string)一样。要解决这个问题就得用1$、2$、3$……这个特性。2$和1$分别代表$format后的第二个参数($location)和第一参数($num)。之所以加上2\$,是因为双引号的字符串中的变量($s和$d)会被替代,所以需要将$转义。如果要避免这个情况,就用单引号。
$format='The %2$s contains %1$d monkeys';
printf($format,$num,$location);