note 69230 deleted from language.control-structures by felipe
| From: | felipe@php.net | Date: | Mon, 10 Dec 2007 18:36:15 +0000 |
| Subject: | note 69230 deleted from language.control-structures by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133291@lists.php.net to get a copy of this message | ||
Note Submitter: jupiter at nospam dot com
----
// 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