1<?php
2$os = array("Apple", "Banana", "Lemon");
3if (in_array("Apple", $os)) {
4 echo "Yeah. Exist Apple";
5}
6if (!in_array("Buleberry", $os)) {
7 echo "Oh, Don't Exist Blueberry!!!";
8}
9?>
1<?php
2/**
3in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) : bool
4*/
5
6$os = array("Mac", "NT", "Irix", "Linux");
7if (in_array("Irix", $os)) {
8 echo "Got Irix";
9}
10if (in_array("mac", $os)) {
11 echo "Got mac";
12}
13?>
14
15
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?>