Thomaschaaf
Thomaschaaf

Reputation: 18196

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 position 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

Upvotes: 0

Views: 919

Answers (2)

Mark Baker
Mark Baker

Reputation: 212412

vprintf("Hello %1$s! I want %3$s t0 be %2$s and %4$s, %5$s", array_merge($array,$arrayb));

Upvotes: 3

rik
rik

Reputation: 8612

Have a look at http://php.net/manual/en/function.vsprintf.php#87031 - different syntax but same goal.

Upvotes: 3

Related Questions