|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-09-05 00:21 UTC] yaXay at gmx dot net
[2010-12-03 17:37 UTC] jani@php.net
-Status: Open
+Status: Closed
-Package: Feature/Change Request
+Package: *General Issues
-Assigned To:
+Assigned To: jani
[2010-12-03 17:37 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 15:00:01 2025 UTC |
Description: ------------ The list of PHP functions that operate on arrays has grown large, but could be restructured to fit into a more coherent model. Multidimensional array operations in any language can be confusing even in the best situations. PHP's array functions seem to have been implemented one at a time, as someone saw a need. Some of the functions are overly specific to a given, rare applicationm and others are not defined well particularly for multidimensional applications. It can be difficult to figure out which function(s) to use/combine to accomplish a particular task. Just as one example, array_slice could be more useful for multidimensional arrays if an array could be given for the offset and length This would allow one to slice, for example, all instances of a particular field in a set of database results. I would propose a new array function set for a later version of PHP, that works the same without regard to dimension. In my experience, the best implementation of array functionality (disregarding the language syntax) that I have ever used is the one in APL. Every function that works on arrays (which is most of them) does what's expected regardless of dimensionality, and in almost all cases every argument can be an array. Like PHP, APL can view a string as a string or as an array of char. Later versions supported structured arrays, akin to objects. I found APL's basic functions to be easier to learn and use than any of the 'Mathematica' clones. Of course APL just represents one potential approach. If nobody else is already working on anything in this line, I'd be amenable to participating in such a project, perhaps first as an extension - though I can't say I'd be that much help. It may be that the APL functions could be used as models for named functions, with similar monadic/dyadic effects; or an interface to the Octave libraries could be the best approach. Reproduce code: --------------- Example of APL equivalents: APL :== function() --> effect or equivalent using PHP syntax A = iota(6) :== iterate (6) --> A = range(6); B = rho (A) :== shape (A) --> B = count (A); B = (2 3) rho (A) :== reshape A --> B = array ( array (0, 1, 2), array ( 3, 4, 5); --> or B = array (range (0,3), range(3,6)); C = (0 1 0 ) select(A) (I forget the APL name) --> C = array (array (1), array (4)); --> no simple equiv in PHP