Numbers and array's

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Numbers and array's

Post 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.
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post 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;?
Dm7
Forum Commoner
Posts: 67
Joined: Sat Oct 08, 2005 9:16 pm
Location: USA

Post 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",
              );
Post Reply