Re: array_search in 2-D array
| From: | Chris Lee | Date: | Thu, 27 Sep 2001 15:00:29 +0000 |
| Subject: | Re: array_search in 2-D array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-69009@lists.php.net to get a copy of this message | ||
ok, I *think* your trying to find the index of the array that contains your
photo ?
function find_index($sess_arrayPhotos, $photo)
{
foreach( $sess_arrayPhotos as $pos => $val
if ( $val['PhotoId'] == $photo )
return $pos;
}
--
Chris Lee
lee@mediawaveonline.com
"Naintara Jain" <naintara.jain@in.velocient.com> wrote in message
news:016301c14748$520bb180$73c8a8c0@eurolink.stpn.soft.net...
> I have a 2D array wherein each row is an associative array (which has keys
that are column names of
> a certain MySQL table)
> the array name is "sess_arrayPhotos".
> I need to match PhotoId (2nd dimension key) for every row (numeric index)
of the 2D array.
>
> I tried--
> $keyPos=array_search($searchedforId,$sess_arrayPhotos);
> --but that didn't work.
>
> Right now, I am achieving it by:
>
> $sess_arrind=0;
> while(($sess_arrayPhotos[$sess_arrind]["PhotoId"] <> $photo) &&
($sess_arrind <
> sizeof($sess_arrayPhotos)))
> {
> next($sess_arrayPhotos);
> $sess_arrind=$sess_arrind+1;
> }
> $keyPos=$sess_arrind;
>
> I would like to know if there is a way of doing this using array_search().
>
> -in anticipation
> -Naintara
>
>