Wednesday, 24 September 2014

array_search in PHP

array_search() function is used to search an array for a specified value, it then returns the key of a corresponding value.

Syntax:

array_search(value,array,strict)

Parameters Description:
value : Required. Specifies the value to search for
array : Required. Specifies an array
strict : Optional.
     Possible values:
  • true
  • false - Default

Example:

<?php
$daysarr1 = array( "a"=>"Sunday","b"=>"Monday","c"=>"Tuesday" );
echo  array_search("Monday",$daysarr1);
echo "<br />";
$daysarr2 = array( "a"=>"9","b"=>"9","c"=>9);
echo  array_search(9,$daysarr2,true);
?>

O/P:


b
c

0 comments:

Post a Comment