Re: Foreach question

From: Date: Fri, 16 Nov 2007 00:50:07 +0000
Subject: Re: Foreach question
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-264666@lists.php.net to get a copy of this message
2007/11/15, Philip Thompson <philthathril@gmail.com>: > > On Nov 15, 2007 5:12 PM, Juan Marcelo Rodríguez < > juan@rodriguezmonti.com.ar> > wrote: > > > Yes, I made a mistake in the first sentence. > > > > The code is : > > [...] > > > > foreach ($equipos as $key => $val){ > > > > echo "<tr><td>"; > > echo "1" . "</td><td>"; // I would like to add the > > counter here > > reeplacing > > "1" > > > echo "<tr><td>".($key+1)."</td><td>"; > > This is assuming $key starts at 0 and increments by 1 each iteration.... > However, if you can't assume that, just have a separate counter: > > <?php > $counter = 0; > foreach ($a as $b => $c) { > echo "<tr><td>".(++$counter)."</td><td>"; > ... > } very good idea. thanks! Juan HTH > ~Philip >

« previous php.general (#264666) next »