Share on Google+Share on Google+

PHP Array_search functions

Advertisement
There are more then hundreds of PHP Array Search functions available in the PHP, which can be used differently according to the programming needs.

Learn PHP Array_search functions

There are more then hundreds of functions available in the PHP, which can be used differently according to the programming needs. If we categories them then we can say that they are five or six type such …built-in functions, variable functions, anonymous functions, array functions etc…

In this post I am discussing about the “array_search” function, which is part of “array functions” available in the PHP. 

In general array_search function searches array, for the given condition (value) and returns key if the condition is true. For example if you are looking for the name of an employee who has the employee ID 6872. How will you do that?

Let’s take a small example in the PHP …

<?php
$array = array(6678 => 'Nick', 3389 => 'Ujjwal', 6872 => 'Jyotsna', 86987 => 'EShan');

$key = array_search('6872', $array);
$key = array_search('6678', $array);  
?>
In the given code you can see that we have created an array type variable, which has assigned both key and value.

Advertisements

Posted on: October 27, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.