Forum Moderators: coopster

Message Too Old, No Replies

array loop

         

bilenkyj

4:25 pm on Oct 1, 2008 (gmt 0)

10+ Year Member



im trying to do the following - script isnt rigght but just to give you an idea

$counter = 1

while(counter!==52){
$cellvalues['$counter'] = $avalue;
$counter++
}

$counter = 1

while(counter!==52){
echo $cellvalues['$counter'];
$counter++
}

Im expecting the array to be built in the first while loop but its not doing it, the only value i get is 52 - its as if the array is overwritten with each loop, i need to build up the arry

1 = value
2 = value
3 = value
etc

can anyone help me out please?

d40sithui

5:36 pm on Oct 1, 2008 (gmt 0)

10+ Year Member



hello,
what exactly are u trying to do?
i see you forgot the dollar sign in front of "counter" here..
while(counter!==52){

RonPK

6:19 pm on Oct 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$cellvalues['$counter']

Try this:
$cellvalues[$counter]

Why? Ref. PHP string type [us3.php.net].

bilenkyj

8:33 am on Oct 2, 2008 (gmt 0)

10+ Year Member



the script only seems to remember and display the last value in the array, its as if the array is overwritten with each look
i cannot seem to resolve this issue, can anyone else help out?

i've tried using $cellvalues = array($counter => $justtheweek);
instead of $cellvalues['$counter'] = $avalue; but isnt helping

bilenkyj

8:36 am on Oct 2, 2008 (gmt 0)

10+ Year Member



i got what i wanted with this in the end

$counter = 1

while(counter!==52){
$cellvalues[$counter] = array($counter => $justtheweek);
$counter++
}

$counter = 1

while(counter!==52){
echo $cellvalues[$counter][$counter];
$counter++
}