Core Function InArray
From Sputnik Wiki
InArray( <array>, <needle>, <strict>, <flag> )
Contents |
Description
Checks if a value exists in an array
Parameters
array
The array to use.
needle
The searched value (Can be an array).
Note:
If needle is a string (or the value in the needle array), the comparison is done in a case-sensitive manner.
(Unless the flag is set to ignore case)
strict
Optional; If true the the array value and the needle must be same TYPE such as both Int32s.
Default: false
flag
Optional; Change how the InArray works
1 = Ignore case on string checks
2 = Use recursion
You can add them together for example:
1 | 2
Default: 0
Return Value
Success: Returns true.
Failure: Returns false.
Remarks
None.
Example
$os = array("Mac", "NT", "Irix", "Linux", 10, array("One", "Two", "Three")); if (inArray($os, "Irix")) echo "Got Irix\n"; else echo "Not Got Irix\n"; if (inArray($os, "mac")) echo "Got mac\n"; else echo "Not Got mac\n"; if (inArray($os, "mac", 0, 1)) echo "(ignoreCase) Got mac\n"; else echo "(ignoreCase) Not Got mac\n"; if (inArray($os, "10")) echo "Got 10\n"; else echo "Not Got 10\n"; if (inArray($os, "10", 1)) echo "(strict) Got 10\n"; else echo "(strict) Not Got 10\n"; if (inArray($os, "Two")) echo "(noRecursion) Got Two\n"; else echo "(noRecursion) Not Got Two\n"; if (inArray($os, "Two", 0, 2)) echo "(Recursion) Got Two\n"; else echo "(Recursion) Not Got Two\n";
Needle as an array
$os = array("Mac", "NT", "Irix", "Linux", 10, array("One", "Two", "Three")); if (inArray($os, array("Linux", "Irix"))) echo "Got Irix or Linux\n"; else echo "Not Got Irix nor Linux\n";