what is array_search() in php?

Answers were Sorted based on User's Feedback



what is array_search() in php?..

Answer / binu.v.pillai

It will search a particular value in an array and if it
find that , it will return corresponding index

<?php
$fruitArray = array(0 => 'orange', 1 => 'apple', 2
=> 'mango', 3 => 'grapes');

$key = array_search('apple', $fruitArray); // $key = 1;
$key = array_search('orange', $fruitArray); // $key = 0;
?>

Is This Answer Correct ?    13 Yes 0 No

what is array_search() in php?..

Answer / 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

More PHP Interview Questions

What are the three parts of an http request?

0 Answers  


Which software is best for php?

0 Answers  


What are the security measures we have to take for our site not to hack by others?

1 Answers   Infosys,


How do you remove duplicates from an array?

0 Answers  


What are the Formatting and Printing Strings available in PHP?

0 Answers  






When do sessions end?

0 Answers  


Tell me how can we display information of a variable and readable by human with php?

0 Answers  


What is the function file_get_contents() usefull for?

0 Answers  


What is php stack?

0 Answers  


What is the main difference between asp net and php?

0 Answers  


Why echo is faster than print in php?

0 Answers  


Can a php code encryted? Is it possible to execute the php file which is encrypted(without decrypting), if so pleaze tell me the way.

3 Answers  


Categories