note 10975 modified in function.key by zak

From: Date: Wed, 10 Oct 2001 06:58:36 +0000
Subject: note 10975 modified in function.key by zak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-18764@lists.php.net to get a copy of this message
[Editor's Note: key() returns NULL when attempting to return an unset key. Use the strict comparison operator to differentiate between NULL and 0 i.e. while ( NULL !== ($key = key ($myArray))) { // do some job } --zak@php.net] Sometimes, the first key of an associative array is numeric zero(or null). Then you can't use key as the following because the very first cycle of the loop cannot be accomplished. while ( $key = key( $myArray ) ) { // do some job } So be careful... --was-- [Editor's Note: Use the strict comparison operator to differentiate between FALSE and 0 i.e. while ( FALSE !== ($key = key ($myArray))) { // do some job } --zak@php.net] Sometimes, the first key of an associative array is numeric zero(or null). Then you can't use key as the following because the very first cycle of the loop cannot be accomplished. while ( $key = key( $myArray ) ) { // do some job } So be careful... http://www.php.net/manual/en/function.key.php

« previous php.notes (#18764) next »