php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #17763 Interpretation of the term "multi-dimensional array"
Submitted: 2002-06-14 09:41 UTC Modified: 2002-07-02 05:45 UTC
From: kristian dot raue at gmx dot de Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.2.1 OS: all
Private report: No CVE-ID: None
 [2002-06-14 09:41 UTC] kristian dot raue at gmx dot de
Hello
I think the term "multi-dimensional array" might be misleading for some people. Wouldn't "nested array" be more precise?

Look at the following sample:

$myArray = array(
"A"=>Array("1"=>"test","2"=>"test","3"=>"test"),
"B"=>Array("1"=>"test","2"=>"test","3"=>"test"),
"C"=>Array("1"=>"test","2"=>"test","3"=>"test"));

In this sample I can "unset($myArray["B"])" which deletes a elements associated with the key "B", but there is no function to delete all elements which are associated with the key "2" in one step. I have to go through all the elements of the ABC-Array and delete each "2"-Element seperatly.

In a multi-dimensional array you could delete (and add)Elements in both dimensions without having to loop through the nested arrays.

PS: I very much like the way PHP organizes Arrays, don't change it. It is just the term that confuses me.

With Regards
Kristian

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-17 18:24 UTC] jmcastagnetto@php.net
Of the scripting languages I've used (Perl, Awk, Python), as well as some programming langs, usually what you call 'nested array' is referred to a 'multi-dimensional array' (sometimes interchangeably).

What you are call 'multi-dimensional array' I would think more of a 'multi-dimensional matrix', which is a totally different concept, and no language I know supports such a structure like that natively. SciPython has support for matrices, and so do some Java libs, etc.

If you know of a language that supports the behavior you point of in their *native* array support, I would like to learn. It will be even more usefule if you got some example C code which can implement such constructs, a patch to php4/ext/standard/array.[ch] will be the ultimate "good thing".

Waiting for feedback
 [2002-06-18 10:22 UTC] jmcastagnetto@php.net
Assigning to myself, while waiting for feedback
 [2002-07-01 10:43 UTC] kristian dot raue at gmx dot de
You are right, "multi-dimensional matrix" is propably a more precise term of what I meant. 

I don't know of a language that supports this behavior in their *native* array support and I don't have any example C code which can implement such constructs.
 [2002-07-01 13:20 UTC] m dot ford at lmu dot ac dot uk
Well, I think I'd agree with "nested array" and "multi-dimensional array".

As for supporting the behaviour, this may (or may not!) be what you're looking for:

In FORTRAN 9x if you declare a 2-dimensional array as:

   INTEGER, DIMENSION(2:5, 3:10) :: values

then you can refer to (for example):

   values(2,:)   ! retrieve first row
   values(:,3)   ! retrieve first column

Similarly, in Algol68 you can declare:

    [2:5, 3:10] INT values;

and refer to:

   values[2,]   # retrieve first row #
   values[,3]   # retrieve first column #

I'm not sure, however, if any of this is relevant, since both these examples of column-slicing apply to multi-dimensional arrays; personally, I wouldn't *expect* this kind of functionality with nested arrays, simply because they are arrays *of* arrays, and not monolithic multi-dimensioned ones.  (In Algol68, it is also possible to declare an "array of arrays", but, from my dim, distant and exceedingly imperfect memory, I don't think you can "column"-slice those in the same way!)

Cheers!

Mike
 [2002-07-01 17:52 UTC] jmcastagnetto@php.net
If you really consider this array behaviour would be a "good thing" then do not submit it as a documentation bug, but as a feature request.

Personally I do not think this type of data structure slicing is difficult to implement with a simple loop in PHP, or with a Matrix extension in C (see GSL for example).

I will reclassify this as a feature request, and see if someone from php-dev decides to do something about this in the code, or just close this report.
 [2002-07-01 18:09 UTC] sniper@php.net
PHP is PHP..let's keep it like that and not make it more cryptic than it is.

 [2002-07-02 05:45 UTC] kristian dot raue at gmx dot de
I totally agree with sniper's view on the topic. That is why I initially wrote: "I very much like the way PHP organizes Arrays, don't change it."

The reason why I submitted a documentation bug is just the terminology. I got confused by the word 'multidimensional' because the array does not behave multidimensionally like a multidimensional matrix would. I still think "nested array" would be more precise. But if nobody else has a problem with the current terminology, is perfectly fine with me to close the report.
 [2002-07-02 10:42 UTC] m dot ford at lmu dot ac dot uk
Oh, yes, I like it the way it is too -- my contribution was in no way advocating a change, but was merely a response to jmcastagnetto@php.net asking:

> If you know of a language that supports the behavior you point of in
> their *native* array support, I would like to learn.

However, at the same time I was agreeing that "multi-dimensional array" is a misleading term for PHP's arrays -- they are, indeed, more accurately "nested arrays" or "arrays of arrays".  But that's a fairly fussy distinction, and if no-one feels inclined to change the documentation, I can live with it.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Nov 04 16:00:01 2025 UTC