Copyright © tutorialspoint.com

PHP Function in_array()

previous
Advertisements

Syntax

in_array ( $value, $array [,$strict ] );

Definition and Usage

The in_array() function searches an array for a specific value. If the third parameter strict is set to TRUE then the in_array() function will also check the types of the $value.

Paramters

ParameterDescription
valueRequired. Value to be search in array.
arrayRequired. Specifies an array
strictOptional. If this parameter is set, the in_array() function searches for the search-string and specific type in the array.

Return Value

This function returns TRUE if the value is found in the array, or FALSE otherwise.

Example

Try out following example:

<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
    echo "Got Irix";
}
if (in_array("mac", $os)) {
    echo "Got mac";
}
?> 

This will produce following result:

Got Irix
previous

Copyright © tutorialspoint.com