User Tools

Site Tools


Sidebar

array:in_array

in_array()

Function to check whether a given value (needle) exists in an array (haystack).

Usage

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
}

Parameters

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

Return Values

Value Meaning
true The value is in the array
false The value is not in the array
array/in_array.txt · Last modified: 2017/05/20 13:00 (external edit)