note 105622 modified in language.operators.assignment by tularis

From: Date: Sat, 03 Sep 2011 16:55:59 +0000
Subject: note 105622 modified in language.operators.assignment by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-182924@lists.php.net to get a copy of this message
[[ Editor's note: You are much better off using the foreach (array_expression as $key => $value) control structure in this case ]] When using <php while ($var = current($array) { #do stuff next($aray) ?> to process an array, if current($array) happens to be falsy but not === false it will still end the loop. In such a case strict typing must be used. Like this: <php while (($var = current($array)) !== FALSE) { #do stuff next($aray) ?> Of course if your array may contain actual FALSE values you will have to deal with those some other way. --was-- When using <php while ($var = current($array) { #do stuff next($aray) ?> to process an array, if current($array) happens to be falsy but not === false it will still end the loop. In such a case strict typing must be used. Like this: <php while (($var = current($array)) !== FALSE) { #do stuff next($aray) ?> Of course if your array may contain actual FALSE values you will have to deal with those some other way. http://php.net/manual/en/language.operators.assignment.php

« previous php.notes (#182924) next »