Re: Strange Array Error

From: Date: Thu, 21 Oct 2004 13:46:08 +0000
Subject: Re: Strange Array Error
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-199977@lists.php.net to get a copy of this message
Shaun The problem is that you've assigned $test_array[] = array(); This means that the first element ($test_array[0]) is an array. You're then trying to add $i to it, as in $test_array[$i] = $test_array[$i] + 1; in terms of types what you're doing is array = array + integer Which doesn't make any sense. If you change the first line to $test_array = array(); Then the individual elements will all be NULL, which evaluates to 0 in an integer context, and you will get the result you expect. Hope this helps Cheers Chris Shaun wrote:
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.


« previous php.general (#199977) next »