here is my code and its working
<?php
$num = 5;
$location = 'tree';
define(format,'There are %d monkeys in the %s');
echo sprintf(format, $num, $location);
?>
but i'm getting
NOTICE Use of undefined constant format - assumed 'format' on line number 6
There are 5 monkeys in the tree
Why?
You need to insert '' while defining a variable
<?php
$num = 5;
$location = 'tree';
define('format','There are %d monkeys in the %s');
echo sprintf(format, $num, $location);
?>
You need to add '
s to avoid the Notice
define('format','There are %d monkeys in the %s');
Standard constant names are in capital letters. You should do -
define('FORMAT','There are %d monkeys in the %s');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.