You are here: Re: lost with arrays « PHP Programming Language « IT news, forums, messages
Re: lost with arrays

Posted by David Haynes on 11/18/93 11:38

windandwaves wrote:
> Hi Folk
>
> I have the following array:
> $m = array();
> $m[0] = array("lodgings", "rooms");
> $m[1] = array("location", "there and away");
> $m[2] = array("functions", "events and groups");
> $m[3] = array("activities", "things to do", "exclusive activities");
> $m[4] = array("enquiries", "tariffs");
> $m[5] = array("download", "media info");
>
> If I have a string from the array, for example, download, and I want to find
> out what number it occures in (i.e. 0 - 5, for download the answer being 5)
> then how do I find out? I looked at the array functions, but I am not sure
> what to use (arrays are new to me).
>
> Also, I saw this function (which may actually help), what is the & doing on
> the first line?
>
> function array_set_current(&$array, $key){
> reset($array);
> while(current($array)){
> if(key($array) == $key){
> break;
> }
> next($array);
> }
> }
>
> TIA
>
> Nicolaas
>
>
function find_word($array, $word) {
// for every set of arrays
for( $i=0; $i < count($array); $i++ ) {
// foreach element in the array expressed as $a
foreach( $m[$i] as $a ) {
// is $a the word we are looking for?
if( $a == $word ) {
// yes, return the index into $m
return $i;
}
}
}
// not found in $m
return -1;
}

The &$array says that the array is passed by reference not by value.
When called this way, any changes to the contents of $array in the
function affect the $array in the calling process. This allows you to
pass back more than one value when a function returns or to modify the
contents of a variable in situ.

-david-

 

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

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