|
|
/* F_SearchArr
* Search for $item in $arr.
* Return -1 if nothing, location in $arr if so.
*
* Copyright (C) 1999 David W. Bettis
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
function F_SearchArr($arr, $item)
{
$result = -1;
for ($i = 0; $i < count($arr); $i++) {
if (strcmp($arr[$i], $item) == 0) {
$result = $i;
}
}
return($result);
}
|
|
| Beginners Array Functions Categories : PHP, Beginner Guides, Arrays | | | quick sort for associative arrays Categories : Algorithms, Arrays, PHP | | | Check for functional file links (broken Files)
Categories : PHP, Data Validation, FTP, Regexps, Arrays | | | Stepping through a numbered array with each() and list() Categories : PHP, Arrays | | | How to load a query result into a PHP Array Categories : PHP, Databases, Arrays, MySQL | | | HTML_Graphs uses PHP to provide a consistent interface for creating HTML based charts. The user of the class sets up arrays that are passed to html_graph() which then takes care of all the messy HTML layout. Categories : Graphics, Arrays, PHP, PHP Classes, Charts and Graphs | | | Single-file PHP news system with automatic folder structure creation Categories : PHP, Filesystem, Arrays | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | translate.php - Assocciative array example, passing a reference to a function. Categories : PHP, Arrays, Languages, Variables | | | Grab images from one or more URLs and save them to a specified local directory. Categories : PHP, Filesystem, Strings, Arrays | | | Pageinfo: Array containing page URI, page query string (parameters), request method (GET or POST) and the complete URI Categories : Variables, PHP Options and Info, Arrays, URLs, PHP | | | PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside. Categories : PHP, Arrays, Variables | | | Function to create a separated list Categories : PHP, Arrays, Strings | | | Filling an array with files from any given directory. This example is for the current PHP script's directory. Categories : PHP, Arrays, Filesystem | | | Weighted Random - Random Scripts usually chose one out of each item, and each item have an equal chance to be chosen. But what if you want an item to be chosed more frequently than other? Categories : PHP, Math., Arrays | |
| |
| | | | | Fredrik Kjell wrote : 294
Should U worry about creating some nice code instead
of protecting already know knowledge?
| | | | Franz Prilmeier wrote : 397
Wouldnt it be better to return true, if item has been found
in the array? That way, the search would perform faster.
| | | | Faro Rasyid wrote :613
this code is quite useful for php3 user...
and Prilmeier Franz is right, it`s better to
return a boolean value
| |
|
|