-1

This is my array. I want to check whether 'NASHIK' is present or not in this array. I have used in_array function but I did not get correct output. Help me to findout solution.

Thanks in advance.

Array
(
    [Neo] => 16686
    [new] => 16799
    [PUNE] => 17371
    [NASHIK] => 17373
)
axiac
  • 68,258
  • 9
  • 99
  • 134
Nikita
  • 437
  • 2
  • 12
  • 2
    [isset](http://php.net/isset)? – Jonnix Aug 30 '17 at 11:03
  • Have you read the documentation of [`in_array()`](http://php.net/manual/en/function.in-array.php)? It searches a value but you want to search a key. You can try [`isset()`](http://php.net/manual/en/function.isset.php) or [`array_key_exists()`](http://php.net/manual/en/function.array-key-exists.php). – axiac Aug 30 '17 at 11:05
  • 1
    Laravel is not involved in this question. – axiac Aug 30 '17 at 11:05
  • @JonStirling Thanks...Isset working for me – Nikita Aug 30 '17 at 11:06
  • @axiac, Thanks...Isset working for me – Nikita Aug 30 '17 at 11:07

1 Answers1

2

You are looking for the key of the array, not the value. That's why in_array() is not the correct one.

You need array_key_exists() for that.

shayan
  • 38
  • 1
  • 6