Reply to Bracketed Search on PHP Array?

Your name:

Reply:


Posted by David T. Ashley on 07/03/07 21:25

I have an array of a few hundred integers, ordered in ascending order.

Given an integer input, I'd like to find the index in the array of the
element $array[$i] such that it is equal to or less than the input but
$array[$i+1] is larger.

I couldn't find a function to deal with arrays that does anything except
look for an exact match.

Are there any built-in functions that will search in a "bracketed" way
rather than look for an exact match?

For example,

$a = array( 10, 50, 250, 1000, 20000, 40000 );

If the input is 20,039 (for example), I'd want the output of the function to
be 4, because $a[4] is the element just below 20,001.

Any such built-in function?
--
David T. Ashley (dta@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)

[Back to original 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

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