Arrays misbehaving!

From: Date: Fri, 30 Aug 2002 21:39:19 +0000
Subject: Arrays misbehaving!
Groups: php.general 
Request: Send a blank email to php-general+get-114700@lists.php.net to get a copy of this message
Can anyone explain why the following code operates the way it does in my comments? <?php $test = array ( 'a' => 'A', 'b' => 'B', 'c' => 'C'); if (array_key_exists(2, $test)) echo "It works by key number!"; // Does not work. if (array_key_exists('c', $test)) echo "It works by key name!"; // Works. print_r(array_keys($test)); // outputs "Array ( [0] => a [1] => b [2] => c ) " ?> Any ideas? According to the documentation, it seems like I should be able to access any key in the array by either name or number (which is what I want to do). -- Cameron

« previous php.general (#114700) next »