Variable Being Reset in For Loop

This is a discussion on Variable Being Reset in For Loop within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I'm trying to increment a variable in a for loop. <--- $startColumn = 5; for($rowLength = 0; $rowLength < $length; $...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-07-2006
studiobl
 
Posts: n/a
Default Variable Being Reset in For Loop

I'm trying to increment a variable in a for loop.

<---
$startColumn = 5;
for($rowLength = 0; $rowLength < $length; $rowLength++){
echo "New row current column : " . $startColumn . "<br />";
$startColumn++;
$newRow[$startRow][] = $startColumn;
echo "New row current column updated: " . $startColumn . "<br />"; }
--->

This outputs:

New row current column :5
New row current column updated:6

New row current column :5
New row current column updated:6...

Why is the $startColumn variable being reset to it's pre-loop value?
How can I increment this value?

Reply With Quote
  #2 (permalink)  
Old 12-07-2006
Norman Peelman
 
Posts: n/a
Default Re: Variable Being Reset in For Loop

"studiobl" <brian@studiobl.com> wrote in message
news:1165526188.990823.54980@80g2000cwy.googlegrou ps.com...
> I'm trying to increment a variable in a for loop.
>
> <---
> $startColumn = 5;
> for($rowLength = 0; $rowLength < $length; $rowLength++){
> echo "New row current column : " . $startColumn . "<br />";
> $startColumn++;
> $newRow[$startRow][] = $startColumn;
> echo "New row current column updated: " . $startColumn . "<br />"; }
> --->
>
> This outputs:
>
> New row current column :5
> New row current column updated:6
>
> New row current column :5
> New row current column updated:6...
>
> Why is the $startColumn variable being reset to it's pre-loop value?
> How can I increment this value?
>


Seems to work for me...

$startRow = 0;
$startColumn = 5;
for($rowLength = 0; $rowLength < 10; $rowLength++){
echo "New row current column : " . $startColumn++ . "<br />";
$newRow[$startRow][] = $startColumn;
echo "New row current column updated: " . $startColumn . "<br />"; }

output:

New row current column : 5
New row current column updated: 6
New row current column : 6
New row current column updated: 7
New row current column : 7
New row current column updated: 8
New row current column : 8
New row current column updated: 9
New row current column : 9
New row current column updated: 10
New row current column : 10
New row current column updated: 11
New row current column : 11
New row current column updated: 12
New row current column : 12
New row current column updated: 13
New row current column : 13
New row current column updated: 14
New row current column : 14
New row current column updated: 15


Norm
---
FREE Avatar hosting at www.easyavatar.com


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:48 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0