note 80005 added to language.operators.logical

From: Date: Sun, 23 Dec 2007 23:23:20 +0000
Subject: note 80005 added to language.operators.logical
Groups: php.notes 
Request: Send a blank email to php-notes+get-133906@lists.php.net to get a copy of this message
worth reading for people learning about php and programming: (adding extras <?php ?> to get highlighted code) about the following example in this page manual: Example#1 Logical operators illustrated ... <?php // "||" has a greater precedence than "or" $e = false || true; // $e will be assigned to (false || true) which is true $f = false or true; // $f will be assigned to false var_dump($e, $f); // "&&" has a greater precedence than "and" $g = true && false; // $g will be assigned to (true && false) which is false $h = true and false; // $h will be assigned to true var_dump($g, $h); ?> _______________________________________________end of my quote... If necessary, I wanted to give further explanation on this and say that when we write: $f = false or true; // $f will be assigned to false the explanation: "||" has a greater precedence than "or" its true. But a more acurate one would be "||" has greater precedence than "or" and than "=", whereas "or" doesnt have greater precedence than "=", so <?php $f = false or true; //is like writting ($f = false ) or true; //and $e = false || true; is the same as $e = (false || true); ?> same goes for "&&" and "AND". If you find it hard to remember operators precedence you can always use parenthesys - "(" and ")". And even if you get to learn it remember that being a good programmer is not showing you can do code with fewer words. The point of being a good programmer is writting code that is easy to understand (comment your code when necessary!), easy to maintain and with high efficiency, among other things. ---- Server IP: 69.147.83.197 Probable Submitter: 190.42.209.66 ---- Manual Page -- http://www.php.net/manual/en/language.operators.logical.php Edit -- https://master.php.net/note/edit/80005 Del: integrated -- https://master.php.net/note/delete/80005/integrated Del: useless -- https://master.php.net/note/delete/80005/useless Del: bad code -- https://master.php.net/note/delete/80005/bad+code Del: spam -- https://master.php.net/note/delete/80005/spam Del: non-english -- https://master.php.net/note/delete/80005/non-english Del: in docs -- https://master.php.net/note/delete/80005/in+docs Del: other reasons-- https://master.php.net/note/delete/80005 Reject -- https://master.php.net/note/reject/80005 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#133906) next »