PHP array_search() function

This function searches a value in an array and returns its key.

Syntax

array_search('value', array_name)

value is the searched value and array_name is the array in which search will perform. It returns the key of the searched value, otherwise returns FALSE.

Example1

<?php
    $arr = array("car", "bus", "truck");
    $key = array_search("truck", $arr);
    echo $key;
?>		

Output :

2

Example2

<?php
    $arr = array("11", "10", "12", "44", "13", "50", "23");
    $key = array_search("12", $arr);
    echo $key;
?>		

Output :

5



Related PHP Functions

PHP array_reverse() function
PHP array_diff() function
PHP array_key_exists() function
PHP array_push() 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