You are here: Re: Can't find built-in PHP function which I know exists... « PHP Programming Language « IT news, forums, messages
Re: Can't find built-in PHP function which I know exists...

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация