Page 1 of 1

Numbers and array's

Posted: Wed Oct 19, 2005 7:56 pm
by anthony88guy
Okay, I was looking over some old scripts. Decided to edit one for a current project. It was a shout box I made awhile ago. I choose to use an array to keep all the posting data. $shout['message'], $shout['ip'], $shout['time'], username is stored elsewhere. It wasn’t working correctly so I decided to start echoing out all the variables.

When I echo'd out $shout['ip'] I received 1. But when I changed the variable to $shoutip, it echo'd out my IP. Same with $shout['time'], do I have to declare something when using numbers in arrays?

Thanks for your help.

Posted: Wed Oct 19, 2005 8:08 pm
by anthony88guy
I added this line: $shout = array(); and now it works fine. When do you have to add this? You cant just go $foo['1'] = 1; $foo['2'] = 2;?

Posted: Wed Oct 19, 2005 9:17 pm
by Dm7
you can do $foo[0] = 1; $foo[1] = 2; etc...

but if you're using associative array like you did then this code is required:

Code: Select all

$foo = array (
            "blah" => "1",
            "foo" => "2",
              );