what is array_search() in php?

Answer Posted / sivanandareddy

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


Syntax:..array_search(value,array,strict)


Parameter Description

value Required. Specifies the value to search for
array Required. Specifies the array to search in
strict Optional. Possible values:
true
false - Default
When set to true, the number 5 is not the same as the string 5 (See example 2)


Example 1

<?php
$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");
echo array_search("Dog",$a);
?>
The output of the code above will be:

a

Example 2

<?php
$a=array("a"=>"5","b"=>5,"c"=>"5");
echo array_search(5,$a,true);
?>
The output of the code above will be:

b

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the importance of parser in php?

610


What is composer install?

596


What is die in php?

563


How is it possible to know the number of rows returned in the result set?

552


Is php object oriented?

512






which will print out the php call stack?

590


Explain what is the use of "echo" in php?

559


Can you define an argument as a reference type?

558


What is x+ mode in fopen() used for?

562


How does php isset work?

533


Is apache needed for php?

511


Do you know what is the difference between the include() and require() functions?

519


What is mysql_real_escape_string used for?

561


Do you know how can php and html interact?

541


What is class extend in php?

544