[PHP] Mutlidimensional Arrays?

Junior Spellweaver
Joined
Nov 9, 2008
Messages
178
Reaction score
5
I've gotta do a research assignment on PHP and I'm just going into the Data Structures of PHP and I'm upto the Arrays, i'm trying to go the extra mile in this class by explaining what an array is and the uses of them and i've reached MultiDimensional Arrays. W3 schools and WebCheatSheet don't really explain them in a way that I think I could be able to convey back. So, what i'm asking is how do you understand Multidimensional Arrays?
 
If you are a maths person, I would picture multidimensional arrays as more complicated matrices (e.g. with more rows and columns) compared to your standard 1-dimensional array, which requires an index to access or a 2-dimensional array consisting of a 'key' and 'value'. It basically allows us to store more data regarding perhaps a specific set, or key - storing other arrays as a value which could also store more arrays in its values. Perhaps this article will help explain it better: InformIT: Using Arrays in PHP > Multidimensional Arrays and http://www.desilva.biz/arrays/multidimen.html
 
Last edited:
Multidimensional arrays are arrays in arrays (in arrays(in arrays(...))). Nothing more.

For example...
PHP:
$multiarray = array("array1" => array("subarray1" => array("subsubarray1" => ...)));
 
If you are a maths person, I would picture multidimensional arrays as more complicated matrices (e.g. with more rows and columns) compared to your standard 1-dimensional array, which requires an index to access or a 2-dimensional array consisting of a 'key' and 'value'. It basically allows us to store more data regarding perhaps a specific set, or key - storing other arrays as a value which could also store more arrays in its values. Perhaps this article will help explain it better: InformIT: Using Arrays in PHP > Multidimensional Arrays and Learning Journal - Create Multidimensional Arrays

They aren't really matrices in a sense that a matrix is strictly 2-dimensional. When there are more dimensions you're usually talking about a space or a group, and infinite dimensional structures are pretty interesting.

Multi-dimensional arrays are mathematically similar to finite cross products of finite groups where. If you don't define them like they above as just "an array within an array" then that also means each element can be an array not not cause it to be an N+1 dimensional array.

Specifically when we're talking in CS about multi-dimensional arrays we mean an N_0xN_1xN_2x...xN_n matrix, where N_i is a natural number (specifically > 0 or the dimension is n-1). The type of the objects are usually less important but indicated nonetheless, and in the case of PHP, arrays are dynamic associative maps of an integer/string key to a mixed value. Because they're dynamic, "multi-dimensional" really doesn't mean much to PHP, you usually just embed whatever data you want into the array. But you can simulate a strict N-dimensional array in PHP for sure.
 
Back