1$myArr = [38, 18, 10, 7, "15"];
2
3echo in_array(10, $myArr); // TRUE
4echo in_array(19, $myArr); // TRUE
5
6// Without strict check
7echo in_array("18", $myArr); // TRUE
8// With strict check
9echo in_array("18", $myArr, true); // FALSE
1in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) : bool
2
3// Without strict check
4echo in_array("18", $myArr); // TRUE
5// With strict check
6echo in_array("18", $myArr, true); // FALSE
1$os = array("Mac", "NT", "Irix", "Linux");
2if (in_array("Irix", $os)) {
3 echo "Got Irix";
4}
5if (in_array("mac", $os)) {
6 echo "Got mac";
7}
1The in_array() function is an inbuilt function in PHP.
2The in_array() function is used to check whether a given value exists in an array or not.
3It returns TRUE if the given value is found in the given array, and FALSE otherwise.
4
5 <?php
6
7$people = array("Peter", "Joe", "Glenn", "Cleveland");
8
9if (in_array("Glenn", $people))
10 {
11 echo "Match found";
12 }
13else
14 {
15 echo "Match not found";
16 }
17
18?>
1$allowedFileType = ['application/vnd.ms-excel','text/xls','text/xlsx','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
2
3if(in_array($_FILES["file"]["type"],$allowedFileType))