Jump to content

array_search: what if the needle is found on key 0?


Full-Demon

Recommended Posts

Hi,

 

I have another array problem:

 

I use array_search in my code. But what if it finds the needle on the first key/value of the array? It will output zero, so how do I know the difference between 'not found' and 'found on the first key'? As both will result in zero.

 

I use this, which is not workin:

 

 

$result= array_search($needle, $array);

 

if ($result !== 0)

{

...

 

 

I use the triple '=' (but than in the form of which it has a leading '!').

 

How can I know for sure its on the first key instead of not found?

 

Thanks in advance :)

 

Full-D

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.