Advanced printf functionality in PHP
Is there a way to get this functionality in PHP? I want to be able to choose the array and the positi开发者_Go百科on it should read out. This is just example code.
<?php
$array[] = "Tim";
$array[] = "Harry";
$arrayb[] = "as";
$arrayb[] = "bla";
$arrayb[] = "zta";
echo printf("Hello %0[0]$s! I want %1[0]$s ti be %0[1]$s and %1[1]$s, %1[2]$s", $array, $arrayb);
#OUTPUT: Hello Tim! I want as to be Harry and bla, zta
Have a look at http://php.net/manual/en/function.vsprintf.php#87031 - different syntax but same goal.
vprintf("Hello %1$s! I want %3$s t0 be %2$s and %4$s, %5$s", array_merge($array,$arrayb));
精彩评论