Jump to content

Print Echo


astralaaron
 Share

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';

Edited by astralaaron
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...