#47330 [Opn->Bgs]: key return value should be specified

From: Date: Wed, 26 Aug 2009 07:24:43 +0000
Subject: #47330 [Opn->Bgs]: key return value should be specified
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-2662@lists.php.net to get a copy of this message
ID: 47330 Updated by: torben@php.net Reported By: thuejk at gmail dot com -Status: Open +Status: Bogus Bug Type: Documentation problem Operating System: All PHP Version: Irrelevant New Comment: key() also returns NULL if the array index currently being examined contains NULL, and therefore gives no useful information as to whether the end of the array has been passed or not. To successfully traverse the array, key() is not the appropriate method. Either of the following will server you better: foreach ($arr as $key => $val) { echo "Got $key => $val\n"; } or reset($arr); while (list($key, $val) = each($arr)) { echo "$key => $val\n"; } Previous Comments: ------------------------------------------------------------------------ [2009-02-06 16:47:19] thuejk at gmail dot com Description: ------------ Currently there is no documented way to check whether an array iterator is pointing beyond the end of the array. It would be nice if key($array) could be counted on to return null if that was the case. key does return null in practice, however the documentation does not specify the fact, making me fear that the behaviour could change in the future. See also http://dk.php.net/manual/en/function.key.php ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47330&edit=1

« previous php.doc.bugs (#2662) next »