How to use array search in PHP

In this article, I will explain how the array_search() function can be used in PHP.
  • 1772

array_search() function in PHP

  • The array_search() function search an array for a value and returns the key.

  • In array_search() function, the comparison is done in a case-sensitive manner, If value is a string,

Syntax

array_search(value,array,strict)

Parameter

  • value value is required parameter. Determine value to be searched.

  • array  array is required parameter. Specifies an array.

  • strict strict is optional parameter. Possible values:

    • true
    • false - Default

Example

The following example show to how the array_search() function can be used in PHP.

<html>

<body>

<h3 style="color: blue;">array_search() function example in PHP</h3>  

    <?php

    $array=array("a"=>"Student","b"=>"Teacher","c"=>"Engg.");

    echo"Search Element Key is : ";

    print_r(array_search("Student", $array));

    ?>

</body>

</html>

 

Output

search.jpg

You may also want to read these related articles here

Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.