PHP in_array() function

This function is used to check the existence of a value in an array or not.

Syntax

in_array(searchvalue, array_name, mode);

The 'searchvalue' is the value to search in the array. 'array_name' is the array in which search will be performed. The mode is optional. If mode is set to true, it also searches type of the search value.

Example

<?php
    $arr = array('car', 'train', 'bus', 'cycle');
    if(in_array('bus', $arr)) {
        echo 'bus exists in the array';
    }
?>

Output -

bus exists in the array



Related PHP Functions

PHP array_reverse() function
PHP array_diff() function
PHP array_key_exists() function
PHP array_push() function
PHP array_search() function
PHP class_exists() function
PHP curl_setopt() function
PHP die() function
PHP dirname() function
PHP each() function
PHP explode() function
PHP file_exists() function
PHP function_exists() function
PHP getenv() function
PHP is_readable() function
PHP ksort() function
PHP mkdir() function
PHP ob_start() function
PHP parse_url() function
PHP str_repeat() function
PHP substr() function




Read more articles


General Knowledge



Learn Popular Language