Re: while-do +array

From: Date: Wed, 31 Oct 2007 15:25:03 +0000
Subject: Re: while-do +array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-263868@lists.php.net to get a copy of this message
On 31/10/2007, Steven Macintyre <steven@steven.macintyre.name> wrote: > Hiya, > > I have the following code ... which only seems to result in one item ... > which is incorrect ... can anyone spot my problem? > > if ($armbase != "") { > $options = explode(",", $armbase); > $text .= '<table ><tr>'; > $get_endRow = 0; > $get_columns = 8; > $get_hloopRow1 = 0; > > do { > if($get_endRow == 0 && $get_hloopRow1++ != 0) { > $text .= '<tr>'; > $text .= '<td valign="top" > width="60">'; > $text .= "<img > src='".e_BASE."images/options/armbase/".$value."'>"; > $text .= '</td>'; > $get_endRow++; > } > if($get_endRow >= $get_columns) { > $text .= '</tr>'; > $get_endRow = 0; > } > } while(list($key,$value) = each($options)); The first time around the loop, both $key and $value are undefined, as you're not setting them until the end condition. But that's not a big deal as nothing gets done first time through the loop except for $get_hloopRow1 getting incremented. The next time through the loop, because $get_hloopRow1 is now not zero, the first conditional gets executed. You add some html and the first value from the array to $text to the string and incremenent $get_endRow. All subsequent times through the loop, nothing gets done because the $get_endRow == 0 condition fails. $get_endRow never gets incrememented again. that help at all? -robin

« previous php.general (#263868) next »