Name PHP specifiers in printf() strings

后端 未结 4 2175
情书的邮戳
情书的邮戳 2021-02-19 18:47

Is there a way in PHP to name my specifiers like in Python?

I want this in PHP:

$foo = array(\'name\' => 24);
printf(\"%(name)d\", $foo);
4条回答
  •  长发绾君心
    2021-02-19 18:53

    the closer core function is vsprintf() to use an array instead of multiple parameter, but you still have to use numbered parameters.

    in the comments of this function docs there is someone who created a function to do what you want vnsprintf() printf+array+named parameters

提交回复
热议问题