PHP argument swapping – %2$s

Arun - 09/02/2020 8:36 AM

PHP argument swapping – %2$s

Files 1

File
php
<?php
$num = 5;
$location = 'tree';
 
$format = 'There are %d monkeys in the %s';
echo sprintf($format, $num, $location);
?>
 
Argument swapping
<?php
$format = 'The %2$s contains %1$d monkeys.
           That\'s a nice %2$s full of %1$d monkeys.';
echo sprintf($format, $num, $location);
?>