|
Posted by Pedro Graca on 10/21/06 20:17
Daz wrote:
> I have seen a function similar to in_array() and array_search() which
> returns the 0-based index number of the specified element if it exists.
>
> Please could someone point me in the right direction?
I don't think there's such a function built-in into PHP;
but you can build your own ...
<?php
function array_function($needle, $array) {
$n = 0;
foreach ($array as $value) {
if ($needle == $value) return $n;
++$n;
}
}
$data = array('name'=>'forty-two', 'dob'=>'2006-10-21', 'eye-color'=>'brown');
$zero_index = (int)array_function('brown', $data);
### if ($zero_index != 2) {
### // error!
### }
?>
What you would use it for is beyond my imagination :)
--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot
[Back to original message]
|