Re: Strange Array Error
| From: | Brent Baisley | Date: | Thu, 21 Oct 2004 13:53:59 +0000 |
| Subject: | Re: Strange Array Error | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-199981@lists.php.net to get a copy of this message | ||
You are making the first element of the array $test_array and array item. An array inside and array.
$test_array[] = array() is the same as $test_array[0] = array()
So what you are trying to do is add $i to an array. Kind of like trying to figure out what happens when you add 1 to the color red.
Try one of these:
$test_array = array()
or
$test_array = array(0,0,0,0,0,0,0)
Basically, drop the brackets. You use brackets to reference and array element, not the array itself.
On Oct 21, 2004, at 9:28 AM, 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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Brent Baisley Systems Architect Landover Associates, Inc. Search & Advisory Services for Advanced Technology Environments p: 212.759.6400/800.759.0577