关于sprintf函数,官网说失败的时候会返回false。一直没遇到了,原来占位符比参数多就会返回false。
php -r 'var_dump(sprintf("%s|%s", 11, 22));' string(5) "11|22" MacBook-Pro-6:~ chuanbo7$ php -r 'var_dump(sprintf("%s|%s", 11));' PHP Warning: sprintf(): Too few arguments in Command line code on line 1 Warning: sprintf(): Too few arguments in Command line code on line 1 bool(false) MacBook-Pro-6:~ chuanbo7$ php -r 'var_dump(sprintf("%s|%s", 11, 22, 33));' string(5) "11|22"