You can mislead Javascript arrays with PHP arrays. In PHP, arrays are very flexible. They can be either numerically indexed, or associative, or even mixed.
array('Item 1', 'Item 2', 'Items 3') // numerically indexed array array('first' => 'Item 1', 'second' => 'Item 2') // associative array array('first' => 'Item 1', 'Item 2', 'third' => 'Item 3')
Other languages ββsee these two as different things, including Javascript. An array in Javascript is always numerically indexed:
['Item 1', 'Item 2', 'Item 3']
An "associative array", also called a Hash or Map, technically an object in Javascript *, works like this:
{ first : 'Item 1', second : 'Item 2' } // object (aka "associative array")
They are not interchangeable. If you need "array keys", you need to use an object. If you do not, you will create an array.
* Technically, this is all an object in Javascript, please postpone this for this argument .;)
deceze Apr 16 '10 at 3:10 2010-04-16 03:10
source share