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

C++, C#, Java, PHP, ect...
Post Reply
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

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

Post 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!
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

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

Post by Callan S. »

well putting in

Code: Select all

$goodnum=array();
$price=array();
Seems to make the errors go away, for now.
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

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

Post by Chris »

Define the variable as an array before using it as one.
Fighting for peace is declaring war on war. If you want peace be peaceful.
Post Reply

Return to “Coding”