Jump to content

Print Echo


astralaaron

Recommended Posts

I understand print returns a value, echo doesn't making it slightly faster.Just wondering if anyone has a practical example of when print() could possibly return false?$example = "";if(print($example)) echo 'printed';else echo 'not printed';I can't get print to return false.. trying to understand it for whatever reason, just to learn.EDIT: i just tried this and thought for sure it would break the loop after the 3rd echo but no.

<?php$darse = array('a','b','c');for($i = 0; $i < 1000; $i++){	if(print($darse[$i])) continue;	else break;}echo 'loop ended';

Link to comment
Share on other sites

Logical operators evaluate expressions that can be evaluated as Boolean values. The && doesn't instruct print() to execute. The print expression executes on its own when control moves past the &&. If the thing to the right of && cannot be evaluated as true or false, you throw a runtime error.So an expression with a return value works. An expression without a return value does not work.I really wish break and continue statements had return values in the same way.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...