PHP 8.4.24 Released!

Voting

: one minus one?
(Example: nine)

The Note You're Voting On

mark at manngo dot net
2 years ago
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';    
?>

<< Back to user notes page

To Top