Re: Putting a stop in a foreach

From: Date: Sun, 09 May 2004 15:47:22 +0000
Subject: Re: Putting a stop in a foreach
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-185745@lists.php.net to get a copy of this message
Hmm, yes I see. Thank you. I guess what I should look at then is getting the key value (internal counter/pointer) in the array going to the foreach. Like this example... $a = array( 1,2,3,17 ); $i =0;/* for illustrative purposes only */ foreach ( $a as $v ) {    echo "\$ a[$i ]=> $v. \n ";    $i ++; } Once I have that key value (internal counter) I should be able to do something with it? What I really want to do (since I can't easily get at the query building the array being passed to the foreach) is get the foreach to stop outputting results at a certain limit. Thanks again, Verdon On 5/9/04 11:34 AM, "Matt Schroebel" <matthew.schroebel@epooch.com> wrote: > It's good to understand what foreach is doing: > <?php > $car['GM'] = 'Impala'; > $car['TOYOTA'] = 'Corolla'; > $car['HONDA'] = 'Civic'; > > foreach ($car as $manufacturer => $ model) { > echo "$manufacturer - $model <br />\n"; > } > ?> > > Results: > GM - Impala > TOYOTA - Corolla > HONDA - Civic > > >

« previous php.general (#185745) next »