|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 16:00:01 2025 UTC |
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