note 48362 deleted from function.setcookie by tularis

From: Date: Sun, 02 Jan 2005 14:12:05 +0000
Subject: note 48362 deleted from function.setcookie by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-82568@lists.php.net to get a copy of this message
Note Submitter: doh! ---- s4t4n at mailinator dot com: > > ie. something like > > > > if($_POST["foo"]) { > > $bar = $_POST["foo"]; > > } else { > > $bar = $_COOKIE["foo"]; > > } > > Why oh why such code when something like the following is a) more readable b) shorter! > > $bar = $_POST["foo"] or $_COOKIE["foo"]; because c) that doesn't work ! $_POST["foo"]=NULL; $_COOKIE["foo"]="doh"; $bar=$_POST["foo"] or $_COOKIE["foo"]; echo $bar; and you won't see "doh" as you would with the if statement above. However, this IS quicker and easier and works: $bar = ($_POST["foo"]?$_POST["foo"]:$_COOKIE["foo"]);

« previous php.notes (#82568) next »