RE: Extracting from arrays - alphabetically
| From: | Tim Ward | Date: | Wed, 18 Jul 2001 08:08:12 +0000 |
| Subject: | RE: Extracting from arrays - alphabetically | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-58413@lists.php.net to get a copy of this message | ||
foreach ($array as $key=>$element)
{ if (your_condition) echo("{$array2[$key]} $element");
}
this is a general solution, but in your case why do you need to use the
array with lastname as the element, why not just test the keys of the first
name array, i.e.
foreach ($array2 as $key=>$element)
{ if (your_condition) echo("$key $element");
}
... and why do you have the 2 arrays in the first place?
Tim Ward
Senior Systems Engineer
Please refer to the following disclaimer in respect of this message:
http://www.stivesdirect.com/e-mail-disclaimer.html
> -----Original Message-----
> From: Kevin Price-Ward [mailto:kevin@tmxnewmedia.com]
> Sent: 17 July 2001 11:24
> To: php-general@lists.php.net
> Subject: Extracting from arrays - alphabetically
>
>
> Hi,
>
> A simple problem for you guys (I think),
>
> I have 2 arrays - firstname and lastname, both have the same
> associative
> index - lastname, I have then performed asort on both to order them
> alphabetically. Now I just need to extract and display the
> array elements
> that have the associative index beginning with A or B or
> whatever is defined
> by $query - thus displaying only names where the lastname
> begins with A etc.
>
> How do I do this?
>
> Thanks for any help you can offer.
>
> Lar
>
>