+ 16
Explain the Output ?
2 Answers
+ 5
So this is my explanation.
(Before you read the answer try to read code below on how things are being executed - especially notice how the last print() statement are being printed normally.) First of all in PHP, a print() returns a value 1.
Keeping that in mind, now let us see the first print statement.
1) print("hey") && print(" ") && print("you"); // you11
this is being treated something like
print(("hey" && print(" " && print("you"))); by the compiler during the execution.
And we know parenthesis has the highest precedence/priority so that the first part that is being executed is print("you") giving "you", then this print(" " && print("you")) is being executed(we know that print() always give 1) so this statement is simply print(1)[(" " && print("you")) equals to 1] and therefore we have something like "you1" as of now. Similarly this print(("hey" && print(" " && print("you"))); is simply print(1) and hence the final output is "you11".
+ 5
<!-- Created by ROHIT KANOJIYAđźđł -->
<?php
print("hey") && print(" ") && print("you"); // you11
echo "<br>";
print(("hey") && print("me")) && print("you"); // meyou1
echo "<br>";
print ("hey" && (print (" " && print "you"))); //you11
echo "<br>";
echo '1' . print '2' + 3; //511
?>
________________________________________
(similarly the rest of the print statements follow the same rule above...)
Except this echo '1' . print '2' + 3; //511
Read this....
https://stackoverflow.com/questions/13737265/explain-the-output-of-echo-2-3-print-3
P. S: I maybe wrong so do wait for the perfect answer. đ