Bug #15468 Updated: problem with array_key_exists

From: Date: Sat, 09 Feb 2002 19:14:25 +0000
Subject: Bug #15468 Updated: problem with array_key_exists
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-79835@lists.php.net to get a copy of this message
ID: 15468 Updated by: paja@onride.com Reported By: paja@onride.com Status: Bogus Bug Type: Arrays related Operating System: Linux d2 2.2.20-ow1-procmax-smp PHP Version: 4.1.1 New Comment: for mfischer@php.net: Can you explain me your words: Simple because 'ap' is NOT a key in the first case. ????? Just don't know, what you mean... Previous Comments: ------------------------------------------------------------------------ [2002-02-09 13:55:52] paja@onride.com first case: array(3) { [1]=> string(2) "ap" [2]=> string(2) "aa" [3]=> string(2) "dd" } second case: array(3) { ["ap"]=> int(1) ["aa"]=> int(2) ["dd"]=> int(3) } Why is this different? Shouldn't this be the same? as Array() definition says: Syntax "index => values", separated by commas, define index and values. index may be of type string or numeric. When index is omitted, a integer index is automatically generated, starting at 0. If index is an integer, next generated index will be the biggest integer index + 1. Note that when two identical index are defined, the last overwrite the first. So I have used in first case the Example 3. 1-based index with array(): $firstquarter = array(1 => 'January', 'February', 'March'); I thing, that the second case definition is wrong and should return error, but as I see, the function array_key_exists works with this... I'm I mad or what??? ------------------------------------------------------------------------ [2002-02-09 13:39:15] mfischer@php.net Simple because 'ap' is NOT a key in the first case. See yourself with var_dump($pole); how the array looks like. ------------------------------------------------------------------------ [2002-02-09 13:20:25] paja@onride.com Hello, I'm trying function array_key_exists in this sample script, but doesn't work: <? $a="ap"; $pole = array(1 => "ap", "aa", "dd"); if (array_key_exists($a, $pole)): echo "The element is in the array"; endif; ?> but when using: $pole = array("ap" => 1, "aa" => 2, "dd" => 3); it's working. Can somebody look at this problem? Thanks, Pavel Hrabal ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=15468&edit=1

« previous php.dev (#79835) next »