Function to check whether a given value (needle) exists in an array (haystack).
To check whether the value exists:
var value = "c"; var array = new Array("a", "b", "c", "d"); if(in_array(value, array)) { //Do something if the value is in the array }
To check whether the value exits and that the value is the same data type:
var value = "c"; var array = new Array("a", "b", "c", "d"); if(in_array(value, array, true)) { //Do something if the value is in the array }
Parameter | Data type | Required | Description |
---|---|---|---|
needle | string | Yes | The value you want to check |
haystack | array | Yes | The array to search the value |
strict | boolean | Set to true if the function needs to match the data type as well as the value. Default is false |
Value | Meaning |
---|---|
true | The value is in the array |
false | The value is not in the array |