note 77411 added to language.operators.logical

From: Date: Tue, 28 Aug 2007 19:04:13 +0000
Subject: note 77411 added to language.operators.logical
Groups: php.notes 
Request: Send a blank email to php-notes+get-129860@lists.php.net to get a copy of this message
Note that PHP's boolean operators *always* return a boolean value... as opposed to other languages that return the value of the last evaluated expression. For example: $a = 0 || 'avacado'; print "A: $a\n"; will print: A: 1 in PHP -- as opposed to printing "A: avacado" as it would in a language like Perl or JavaScript. This means you can't use the '||' operator to set a default value: $a = $fruit || 'apple'; instead, you have to use the '?:' operator: $a = ($fruit ? $fruit : 'apple'); ---- Server IP: 64.71.164.2 Probable Submitter: 66.186.116.126 ---- Manual Page -- http://www.php.net/manual/en/language.operators.logical.php Edit -- https://master.php.net/note/edit/77411 Del: integrated -- https://master.php.net/note/delete/77411/integrated Del: useless -- https://master.php.net/note/delete/77411/useless Del: bad code -- https://master.php.net/note/delete/77411/bad+code Del: spam -- https://master.php.net/note/delete/77411/spam Del: non-english -- https://master.php.net/note/delete/77411/non-english Del: in docs -- https://master.php.net/note/delete/77411/in+docs Del: other reasons-- https://master.php.net/note/delete/77411 Reject -- https://master.php.net/note/reject/77411 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129860) next »