RE: [PHP] Strange Array Error

From: Date: Thu, 21 Oct 2004 14:04:46 +0000
Subject: RE: [PHP] Strange Array Error
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-199985@lists.php.net to get a copy of this message
Oh @#*! Thanks Greg, I always get that one wrong ! $test_array = array(); :) > -----Original Message----- > From: Graham Cossey [mailto:graham@cossey.plus.com] > Sent: 21 October 2004 14:48 > To: Shaun; php-general@lists.php.net > Subject: RE: [PHP] Strange Array Error > > > [snip] > > > > Hi, > > > > I have been trying for the past two hours to understand why I get > > an error > > with the following code: > > > > <?php > > $test_array[] = array(); > > $i = 0; > > while($i < 7){ > > $test_array[$i] += $i; > > echo '$day_total[$i] = '.$day_total[$i].'<br>'; > > } > > ?> > > > > Fatal error: Unsupported operand types in > > /usr/home/expensesystem/public_html/test.php on line 5 > > > > I am trying to create a loop where $i is added to array element $i, and > > can't find any information relating to this on google or php.net... > > > > Thanks for your advice. > > Try this: > <?php > $test_array[] = array(); > $i = 0; > while($i < 7){ > $test_array[$i] = $i; > echo '$test_array[$i] = '.$test_array[$i].'<br>'; > $i++; > } > ?> > > PHP objected to the use of += > You did NOT want to increment $i before doing the echo anyway, did you? > > Graham > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#199985) next »