note 69230 added to language.control-structures
| From: | jupiter at nospam dot com | Date: | Mon, 28 Aug 2006 08:46:00 +0000 |
| Subject: | note 69230 added to language.control-structures | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116418@lists.php.net to get a copy of this message | ||
// assigning a variable inside an IF conditional does assign the value,
// then if it evaluates to true, continues to the true statement group
<?php
$a = array(1, 2, ' ', true, 0, '', false, array());
foreach ($a as $b) {
if ($c[] = $b) {
echo 'true, ';
} else {
echo 'false, ';
}
}
print_r($c);
/* RETURNS
true, true, true, true, false, false, false, false
Array
(
[0] => 1 // integer
[1] => 2 // integer
[2] => // a single space
[3] => 1 // boolean true
[4] => 0 // integer
[5] => // nothing
[6] => // nothing
[7] => array()
)
*/
?>
// Notice $c[4] and $c[7] are assigned values, but then evaluate to false
----
Server IP: 64.71.164.2
Probable Submitter: 68.104.56.193
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/language.control-structures.php
Edit -- https://master.php.net/note/edit/69230
Del: integrated -- https://master.php.net/note/delete/69230/integrated
Del: useless -- https://master.php.net/note/delete/69230/useless
Del: bad code -- https://master.php.net/note/delete/69230/bad+code
Del: spam -- https://master.php.net/note/delete/69230/spam
Del: non-english -- https://master.php.net/note/delete/69230/non-english
Del: in docs -- https://master.php.net/note/delete/69230/in+docs
Del: other reasons-- https://master.php.net/note/delete/69230
Reject -- https://master.php.net/note/reject/69230
Search -- https://master.php.net/manage/user-notes.php