RE: [PHP] Foreach question

2011-07-06 Thread Dajka Tamás
.com] Sent: Tuesday, July 05, 2011 5:47 PM To: Robert Cummings Cc: Dajka Tamás; php-general@lists.php.net Subject: Re: [PHP] Foreach question Just use count($arr) in your for-header, as it get's executed again for each loop. 1), array('id'=>2))

Re: [PHP] Foreach question

2011-07-05 Thread Robert Cummings
On 11-07-05 11:46 AM, Louis Huppenbauer wrote: Just use count($arr) in your for-header, as it get's executed again for each loop. 1), array('id'=>2)); for($i=0;$i $arr[$i]['id']+1); } } ?> Ok, so the extents are being updated on each pass of the loop :) Ch

Re: [PHP] Foreach question

2011-07-05 Thread Louis Huppenbauer
Just use count($arr) in your for-header, as it get's executed again for each loop. 1), array('id'=>2)); for($i=0;$i $arr[$i]['id']+1); } } ?> 2011/7/5 Robert Cummings : > On 11-07-05 10:48 AM, Dajka Tamás wrote: >> >> Thanks, that was interesting :) I think I got o

Re: [PHP] Foreach question

2011-07-05 Thread Stuart Dallas
On Tue, Jul 5, 2011 at 2:40 PM, Dajka Tamas wrote: > I've bumped into an interesting thing with foreach. I really don't know, if > this is normal working, or why it is, so I got curious. > > The script: > > foreach ( $cats as &$c ) { > echo $c['id']; > if ( $c['id'] <

Re: [PHP] Foreach question

2011-07-05 Thread Robert Cummings
On 11-07-05 10:48 AM, Dajka Tamás wrote: Thanks, that was interesting :) I think I got one step further in understanding PHP :) BTW, I've changed the loop to 'for' and it's working well :) Can you show us your for loop? I'm not immediately sure how you use a for loop to traverse a growing nu

Re: [PHP] Foreach question

2011-07-05 Thread Robert Cummings
On 11-07-05 09:40 AM, Dajka Tamas wrote: foreach ( $cats as&$c ) { echo $c['id']; if ( $c['id']< 5 ) { $c['id']++; $cats[] = $c; } } Given that you seem to want the above functi

RE: [PHP] Foreach question

2011-07-05 Thread Dajka Tamás
Dajka Tamás Cc: php-general@lists.php.net Subject: Re: [PHP] Foreach question On 11-07-05 10:39 AM, Dajka Tamás wrote: > Ok, but if it would be that way I shouldn't get '122334455' for second > output, no? The item count increments with every iteration of the loop. > > Or yo

Re: [PHP] Foreach question

2011-07-05 Thread Robert Cummings
On 11-07-05 10:39 AM, Dajka Tamás wrote: Ok, but if it would be that way I shouldn't get '122334455' for second output, no? The item count increments with every iteration of the loop. Or you're saying that, it checks for an existance of nextitem before every loop, and that will fail with just

Re: [PHP] Foreach question

2011-07-05 Thread Robert Cummings
On 11-07-05 10:39 AM, Dajka Tamás wrote: Ok, but if it would be that way I shouldn't get '122334455' for second output, no? The item count increments with every iteration of the loop. Or you're saying that, it checks for an existance of nextitem before every loop, and that will fail with jus

RE: [PHP] Foreach question

2011-07-05 Thread Dajka Tamás
l always return true with two elements? ( since the first elements copy is pushed as third element, etc ) -Original Message- From: Robert Cummings [mailto:rob...@interjinn.com] Sent: Tuesday, July 05, 2011 4:28 PM To: Dajka Tamás Cc: php-general@lists.php.net Subject: Re: [PHP] Foreach q

Re: [PHP] Foreach question

2011-07-05 Thread Louis Huppenbauer
I don't think that it does this: if ( count($elements) == 1 ) then loop 1; else loop normally; It's probably more something like that: $i=count($elements); loop: $i--; if($i == 0) $last_loop = true; else $last_loop = false if($last_loop) exit; else goto loop; But aside from tha

Re: [PHP] Foreach question

2011-07-05 Thread Robert Cummings
On 11-07-05 10:20 AM, Dajka Tamás wrote: Hi, Yeah, I'm really want to do that, since I'm working with the elements of the original array ( skipped that part in sample code ). I've tried your suggestion, but it gives the same result, so on just one input is just gives back '1'. Ahhh... you w

RE: [PHP] Foreach question

2011-07-05 Thread Dajka Tamás
= $c; } } But this is 'while' and it pops all elements from the array... Cheers, Tamas -Original Message- From: Louis Huppenbauer [mailto:louis.huppenba...@gmail.com] Sent: Tuesday, July 05, 2011 4:12 PM To: Robert Cummings Cc: Dajka Tamas; php-general@lists.p

RE: [PHP] Foreach question

2011-07-05 Thread Dajka Tamás
e same with each case ) Cheers, Tamas -Original Message- From: Robert Cummings [mailto:rob...@interjinn.com] Sent: Tuesday, July 05, 2011 4:06 PM To: Dajka Tamas Cc: php-general@lists.php.net Subject: Re: [PHP] Foreach question On 11-07-05 09:40 AM, Dajka Tamas wrote: > Hi a

Re: [PHP] Foreach question

2011-07-05 Thread Louis Huppenbauer
Or maybe he tried to do the following? ($c['id'] + 1)); } } ?> 2011/7/5 Robert Cummings : > > On 11-07-05 09:40 AM, Dajka Tamas wrote: >> >> Hi all, >> >> >> >> I've bumped into an interesting thing with foreach. I really don't know, >> if >> this is normal working, or why it is,

Re: [PHP] Foreach question

2011-07-05 Thread Robert Cummings
On 11-07-05 09:40 AM, Dajka Tamas wrote: Hi all, I've bumped into an interesting thing with foreach. I really don't know, if this is normal working, or why it is, so I got curious. The script: foreach ( $cats as&$c ) { echo $c['id']; if ( $c['id']< 5 )

Re: [PHP] Foreach question

2011-07-05 Thread Louis Huppenbauer
Hi there I think that foreach in your first example just knowns that this should be the last loop (as the array only contains 1 element at start) and so stops there. In your 2nd example however the first loop isn't the last, so the array get's checked again, and now there's another element, so...

Re: [PHP] foreach question

2008-07-29 Thread Jason Pruim
On Jul 29, 2008, at 3:33 PM, Daniel Brown wrote: On Tue, Jul 29, 2008 at 3:25 PM, Jason Pruim <[EMAIL PROTECTED]> wrote: function random($random){ $randomQuery = "SELECT * FROM `current` ORDER BY Rand() LIMIT 2"; $result = mysql_query($randomQuery); $row[] = $result; forea

Re: [PHP] foreach question

2008-07-29 Thread Micah Gersten
You cannot do this: $row[] = $result; You need to loop around this: $row = mysql_fetch_assoc($result); Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com Jason Pruim wrote: > Hey Everyone... > > So I am attempting to pull 2 random records from a MySQL databa

Re: [PHP] foreach question

2008-07-29 Thread Daniel Brown
On Tue, Jul 29, 2008 at 3:25 PM, Jason Pruim <[EMAIL PROTECTED]> wrote: > > function random($random){ > >$randomQuery = "SELECT * FROM `current` ORDER BY Rand() LIMIT 2"; > >$result = mysql_query($randomQuery); > $row[] = $result; > > > foreach($row as $key => $value) { > $random[$k

Re: [PHP] Foreach question

2007-11-16 Thread Jeremy Mcentire
On Nov 15, 2007, at 7:50 PM, Juan Marcelo Rodríguez wrote: 2007/11/15, Philip Thompson <[EMAIL PROTECTED]>: On Nov 15, 2007 5:12 PM, Juan Marcelo Rodríguez < [EMAIL PROTECTED]> wrote: Yes, I made a mistake in the first sentence. The code is : [...] foreach ($equipos as $key => $val){ echo ""

Re: [PHP] Foreach question

2007-11-15 Thread Michael McGlothlin
$x = 0; foreach ( $blah as $bleh ) { $x = $x + 1; print "$x: $bleh"; } HI, I'm working with an associative array, and generating its data a form. I use foreach to loops the contents of the array and echo to print the table and the data. Everything goes well, however I would like to add a counter

Re: [PHP] Foreach question

2007-11-15 Thread Stut
Juan Marcelo Rodríguez wrote: I'm working with an associative array, and generating its data a form. I use foreach to loops the contents of the array and echo to print the table and the data. Everything goes well, however I would like to add a counter to print the row's number. The question : Am

Re: [PHP] Foreach question

2007-11-15 Thread Philip Thompson
On Nov 15, 2007 5:12 PM, Juan Marcelo Rodríguez <[EMAIL PROTECTED]> wrote: > Yes, I made a mistake in the first sentence. > > The code is : > [...] > > foreach ($equipos as $key => $val){ > > echo ""; > echo "1" . ""; // I would like to add the counter here > reeplacing > "1" echo "".($key+1)."

Re: [PHP] Foreach question (solved)

2007-11-15 Thread Juan Marcelo Rodríguez
Thanks. I solved it using this : $x = 0; foreach ($equipos as $key => $val){ $x = $x + 1; echo ""; echo $x . ""; 2007/11/15, Michael McGlothlin <[EMAIL PROTECTED]>: > > $x = 0; > foreach ( $blah as $bleh ) { > $x = $x + 1; > print "$x: $bleh"; > } > > > HI, > > I'm working with an associative

Re: [PHP] Foreach question

2007-11-15 Thread Juan Marcelo Rodríguez
2007/11/15, Philip Thompson <[EMAIL PROTECTED]>: > > On Nov 15, 2007 5:12 PM, Juan Marcelo Rodríguez < > [EMAIL PROTECTED]> > wrote: > > > Yes, I made a mistake in the first sentence. > > > > The code is : > > [...] > > > > foreach ($equipos as $key => $val){ > > > > echo ""; > > echo "1" . ""; //

Re: [PHP] Foreach question

2007-11-15 Thread Juan Marcelo Rodríguez
Yes, I made a mistake in the first sentence. The code is : [...] foreach ($equipos as $key => $val){ echo ""; echo "1" . ""; // I would like to add the counter here reeplacing "1" print "" . ""; echo $key . ""; print "" . ""; echo $val . ""; print "" . ""; } ?> I use the array to generate the

Re: [PHP] foreach question

2007-04-10 Thread Richard Lynch
On Sun, April 8, 2007 6:29 pm, [EMAIL PROTECTED] wrote: > I have .. > > foreach( $_POST as $key ) { > echo "$key"; > } You are actually echoing out the VALUE, not the KEY... > and that gives me > > item1 > item2 > item3 > item4 > item5 Unless your VALUE has "item1\nitem2\nitem3\nitem4\nitem5

Re: [PHP] foreach question

2007-04-08 Thread siavash1979
; > > Whois Results: > > > > > > > foreach( $_POST as $key ) { > >echo "$key"; > > } > > ?> > > > > > > > > > > - Original Message - From: "Lori Lay" <[EMAIL PROTECTED]>

Re: [PHP] foreach question

2007-04-08 Thread Lori Lay
"; } ?> - Original Message - From: "Lori Lay" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Cc: Sent: Monday, April 09, 2007 5:20 AM Subject: Re: [PHP] foreach question [EMAIL PROTECTED] wrote: "both examples do the same thing.." no, ex1 only

Re: [PHP] foreach question

2007-04-08 Thread chris
; Cc: Sent: Monday, April 09, 2007 5:20 AM Subject: Re: [PHP] foreach question [EMAIL PROTECTED] wrote: "both examples do the same thing.." no, ex1 only has 1 so outputs like.. item1item2item3item4item5 Where as I want this.. item1 item2 item3 item4 item5 ie a line break after e

Re: [PHP] foreach question

2007-04-08 Thread Lori Lay
o the list. Lori - Original Message - From: "Sebe" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Cc: Sent: Monday, April 09, 2007 1:22 AM Subject: Re: [PHP] foreach question [EMAIL PROTECTED] wrote: I have .. foreach( $_POST as $key ) {echo "$key"; }

Re: [PHP] foreach question

2007-04-08 Thread siavash1979
double quotes). > > > > - Original Message - From: "Sebe" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > Cc: > > Sent: Monday, April 09, 2007 1:22 AM > > Subject: Re: [PHP] foreach question > > > > > >>

Re: [PHP] foreach question

2007-04-08 Thread Sebe
> To: <[EMAIL PROTECTED]> Cc: Sent: Monday, April 09, 2007 1:22 AM Subject: Re: [PHP] foreach question [EMAIL PROTECTED] wrote: I have .. foreach( $_POST as $key ) {echo "$key"; } and that gives me item1 item2 item3 item4 item5 how do I write it to give me item1 ite

Re: [PHP] foreach question

2007-04-08 Thread chris
;[EMAIL PROTECTED]> Cc: Sent: Monday, April 09, 2007 1:22 AM Subject: Re: [PHP] foreach question [EMAIL PROTECTED] wrote: I have .. foreach( $_POST as $key ) {echo "$key"; } and that gives me item1 item2 item3 item4 item5 how do I write it to give me item1 item2 item3 item4

Re: [PHP] foreach question

2007-04-08 Thread Sebe
[EMAIL PROTECTED] wrote: I have .. foreach( $_POST as $key ) {echo "$key"; } and that gives me item1 item2 item3 item4 item5 how do I write it to give me item1 item2 item3 item4 item5 Thanks both examples do the same thing.. -- PHP General Mailing List (http://www.php.net/) To unsubs