tags:

views:

80

answers:

4

Can you say that associative arrays in PHP are like 2D arrays?

+6  A: 

No, they are still one-dimensional just like regular 0-based arrays. The difference is that you aren't limited to integers for the keys; you can use any arbitrary string.

And strictly speaking there isn't a technical distinction between associative and non-associative arrays. They use the same syntax, it's just your choice whether you use integers or strings or both for the keys.

John Kugelman
A: 
$var[$x] = 1-dimensional
$var[$y][$y2] = 2-dimensional
$var[$z][$z2][$z3] = 3-dimensional

It doesn't matter if $x, $y or $z are numeric or strings, actually.

Martin Hohenberg
A: 

A 2D array is more like a matrix, a plane, a coordinate system. An associative array on the other hand could be called a dictionary or hash.

The MYYN
A: 

From wikipedia Associative array

An associative array (also associative container, map, mapping, dictionary, finite map, and in query-processing an index or index file) is an abstract data type composed of a collection of unique keys and a collection of values, where each key is associated with one value (or set of values).

So an associative array is actually an ADT, implemented in another way. Instead, a 2d array "really" has two dimensions and is, usually, a primitive type.

klez