Page 1 of 1

'Warning: Cannot use a scalar value as an array'? (solved)

Posted: Mon Oct 28, 2013 1:15 am
by Callan S.
I'm not quite sure as to the reasons it's giving this error

Code: Select all

$goods[1]="";
$goods[2]="";
$goodnum[1]=0;
$goodnum[2]=0;
$price[1]=0;
$price[2]=0;
It only complains about $goodnum[1] & [2] and $price[1] & [2]. But not $goods[1] & [2]??

I could have sworn I've used arrays like this in PHP before and it's been fine...

Can anyone help me out - I just need a short array since latter in the code I have a very short for loop do the same thing twice, but with two different sets of data. Thanks!

Re: 'Warning: Cannot use a scalar value as an array'? (solve

Posted: Mon Oct 28, 2013 5:43 am
by Callan S.
well putting in

Code: Select all

$goodnum=array();
$price=array();
Seems to make the errors go away, for now.

Re: 'Warning: Cannot use a scalar value as an array'? (solve

Posted: Wed Oct 30, 2013 1:17 pm
by Chris
Define the variable as an array before using it as one.