Re: Looping through array

From: Date: Thu, 16 Nov 2006 20:30:08 +0000
Subject: Re: Looping through array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-244744@lists.php.net to get a copy of this message
<?php $arr = array(5, 4, 3, 2, 1, 10, 9, 8, 7, 6,); echo '<table border="1">'; echo '<tr>'; for ($x=0,$y=sizeof($arr); $x<$y; ++$x) { echo "<td>{$arr[$x]}</td>"; if ($x == 4) { echo '</tr><tr>'; } } echo '</tr>'; echo '</table>'; ?> On Nov 16, 2006, at 1:19 PM, Ashley M. Kirchner wrote:
Say I have an array containing ten items, and I want to display them in a table as follows:
    5 4 3 2 1
10 9 8 7 6 What's the best way to loop through that array to do that? My thinking gets me to create a loop for 5 through 1, repeated twice, and the second time I add '5' to the index value. There's got to be a saner way... --W | It's not a bug - it's an undocumented feature. +-------------------------------------------------------------------- Ashley M. Kirchner <mailto:ashley@pcraft.com> . 303.442.6410 x130
 IT Director / SysAdmin / Websmith             .     800.441.3873 x130
 Photo Craft Imaging                       .     3550 Arapahoe Ave. #6
 http://www.pcraft.com ..... .  .    .       Boulder, CO 80303, U.S.A.
--PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Darrell Brogdon darrell@brogdon.net http://darrell.brogdon.net *************************************
** Prepare for PHP Certication!    **
** http://phpflashcards.com        **
*************************************

« previous php.general (#244744) next »