You are here: Re: looping two arrays « PHP Programming Language « IT news, forums, messages
Re: looping two arrays

Posted by Erwin Moller on 10/23/06 15:52

stefano.troiani@gmail.com wrote:

> Hi,
>
> i have two arrays and I would like to loop both of them one inside the
> other.
> The first one comes from a readdir and present an array with the
> document's names, the second one is an array with the names i want to
> appear for that documents as a link.
> My need is to sort both of them so that i got something like this:
> <a href="first element of array 1" > first element of array 2</a>
> <a href="second element of array 1" > second element of array 2</a>
> .........................................
>
> but i don't know how to do it.
>
> Thanks for any help,
>
> stefano

Hi Stefano,

That is very straightforward.
I assume the arrays are both the same length.
(if not your setup makes little sense.)

<?
// both arrays are filled by your code
$arrHyperlink = array(.....);
$arrHyperlinkText = array(.....);

for ($i=0;$i<count($arrHyperlink);$i++){
?>
<a href="<?= $arrHyperlink[$i] ?>"><?= $arrHyperlinkText[$i] ?></a>
<?
}
?>

Simple he? Or did I miss someting? (Happens the whole day to me. :P)

Regards,
Erwin Moller

 

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

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