note 128857 added to function.print
| From: | mark at manngo dot net | Date: | Tue, 05 Sep 2023 04:34:34 +0000 |
| Subject: | note 128857 added to function.print | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220818@lists.php.net to get a copy of this message | ||
The other major difference with echo is that print returns a value, even itâs always 1.
That might not look like much, but you can use print in another expression. Here are some examples:
<?php
rand(0,1) ? print 'Hello' : print 'goodbye';
print PHP_EOL;
print 'Hello ' and print 'goodbye';
print PHP_EOL;
rand(0,1) or print 'whatever';
?>
Hereâs a more serious example:
<?php
function test() {
return !!rand(0,1);
}
test() or print 'failed';
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.157.134 (proxied: 159.196.219.235)
----
Manual Page -- https://php.net/manual/en/function.print.php
Edit -- https://main.php.net/note/edit/128857
Del: integrated -- https://main.php.net/note/delete/128857/integrated
Del: useless -- https://main.php.net/note/delete/128857/useless
Del: bad code -- https://main.php.net/note/delete/128857/bad+code
Del: spam -- https://main.php.net/note/delete/128857/spam
Del: non-english -- https://main.php.net/note/delete/128857/non-english
Del: in docs -- https://main.php.net/note/delete/128857/in+docs
Del: other reasons-- https://main.php.net/note/delete/128857
Reject -- https://main.php.net/note/reject/128857
Search -- https://main.php.net/manage/user-notes.php