Tutorials Point


  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

PHP Function array_search()


previous

Advertisements

Syntax

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

Definition and Usage

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

If value is a string, the comparison is done in a case-sensitive manner.

Paramters

ParameterDescription
valueRequired. Specifies a value to be searched.
arrayRequired. Specifies an array.
strictOptional. If it is set to TRUE then the array_search() will also check the types of the search in the array.

Return Values

Returns the key if it is found in the array, FALSE otherwise.

Example

Try out following example:

<?php
$array=array("a"=>"banana","b"=>"apple","c"=>"orange");

print_r(array_search("apple", $array));
?> 

This will produce following result:

b

previous Printer Friendly

Advertisements


  

Advertisements