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
webmonkey88
Forum Newbie
Posts: 20 Joined: Fri Aug 14, 2009 4:30 am
Post
by webmonkey88 » Sun Aug 16, 2009 7:17 am
Just come across something that is a little weird, just noticed that you can do the following with arrays:
Code: Select all
$myarray = array(1 => 1, 2=> 2, 3 => 3, 4 => 4);
$myarray{5} = 5;
//array now has key 5 value 5 as if i had done $myarray[5] = 5
why can you use {} as well as [], but if i use it like the following it will throw a syntax error:
Anyone know where i can find some information on this i have googled but cant find anything.
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Sun Aug 16, 2009 7:46 am
I read this in the manual a while ago...can't remember which page.
But yeah, you can use curly or square parenthesis for array keys.
wpsd2006
Forum Commoner
Posts: 66 Joined: Wed Jan 07, 2009 12:43 am
Post
by wpsd2006 » Sun Aug 16, 2009 9:37 am
wow that's new
that might be easier then
But I think we shouldn't use it after we find a real documentation with this cuz let say it's a bug and get deprecated......
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Sun Aug 16, 2009 10:44 am
Well it's not a bug. I'm sure they realise this happens.
Although i think the method of using them to access a character in a string is deprecated...so people don't use it as much as square brackets.
i could be wrong though. Can't remember where that damn page is...
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Sun Aug 16, 2009 12:41 pm
Oh cool, I was right