PHP arrays
Posted: 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:
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.
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:
Code: Select all
$myarray{} = 5;