Jump to content

array_key_exists behavior


ennemkay

Recommended Posts

The array_key_exists() function returns whether the array has the specified key, or not. To steal a comment from the manual, "An array in PHP is … a type that associates values to keys." (http://php.net/arrays). In your example, your array has only one value "a" and its key is 0.

 

It looks like the function you really wanted was in_array() (http://php.net/in_array), which returns whether the array as the specified value, or not.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.