Could you explain why 'print' in PHP return 1?
For what? Was it the result of simple creativity? Or maybe, "we have created, and you can do with that whatever you wish"?
For example,
$a = print('4');
var_dump($a);
Could you explain why 'print' in PHP return 1?
For what? Was it the result of simple creativity? Or maybe, "we have created, and you can do with that whatever you wish"?
For example,
$a = print('4');
var_dump($a);
From the docs
Returns 1, always.
Why Should I use print? What kind of Advantage?
Both print
and echo
are language constructs and echo
is even faster than print
. But the advantage of print
is that it is more flexible than echo and it can do anything that echo can do.
The simplest example is, print
can be used in an expression like ternary.
($someValue) ? print('somevalue is True') : print('someValue is false');
This is because as I stated above print always returns 1
and echo doesn't have a return value
.
Read Official Documentation Here: