Tag Archives: in_array() function in php

what is in_array() function in php ?

27 Dec

In php , in_array() function is used to search record from specified array .If that record found in an array then , in_array() function will return TRUE , else it will return FALSE.

Syntax :
<?php
in_array( specific record , array );
?>

Output :

bool ( TRUE or FALSE )

Lets have the following example:

Example :
$languages = array("PHP","MySQL","Ajax","Javascript");

if (in_array("MySQL", $languages)) {
    echo "MySQL record found in given array";
}
Answer : 
In the above example $languages is defined as an array with 4 different value.
In the if condition in_array() is used to check MySQL keyword within $languages array.
Since MySQL is present in $languages.
Output will be :
MySQL record found in given array