php array performance



Does anyone know if there is any way to improve php array performance?

I am currently developing an application which uses very large
multidimensional arrays, with many multiple dimensions. I am rapidly
discovering that php seems to be quite weak in this area.

I have finally found a way to "allocate" the memory for php arrays
reasonably quickly and efficiently. The following code segment runs in
approx 0.03seconds and doesn't use too much memory ~ 20mb.

$array = array_fill(0,1,array_fill(0,73,array_fill(0,100001,0.01)));

However if I try to fill the array using a bunch of nested loops it uses
100s of mbs and takes a lot longer to execute. Plus if I want to change any
values within this array structure it seems to have the same effect (poor
performance). It seems like due to the way arrays are implemented within php
the environment rebuilds the array in memory everytime you make any change
to an element within the array; which is expensive.

After much reading around the subject it seems that arrays in php are not
*really* arrays at all but hash-tables, or "maps" according to the
documentation.

Does anyone know if there is any alternative data-structures to the array in
php that work more efficiently in multiple dimensions, or any other thoughts
on overcoming this problem. If I don't figure it out I'm probably going to
have to rewrite the thing in CGI/C++ to get the array performance; which I
would rather not do.

Thanks in advance.


.



Relevant Pages

  • Re: Need help on PHP for MPE/ix
    ... Here is the syntax of the dbupdate intrinsic in PHP: ... assoc array of item values) ... Please let me know if you have any more suggesstions to solve this problem. ... Pavan Kumar Rati wrote: ...
    (comp.sys.hp.mpe)
  • Re: Using a RegEx as a "variable" WITHIN an array?
    ... believe the PHP one is also based upon. ... combination of 1 or more numerics in this instance would give you your ... add this to your array - you could then do a pattern match on the array ... > Dim selCriteria as String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Need help on PHP for MPE/ix
    ... If one item is an array, it must be declared as such in the list ... So, please show us the declaration of the record buffer, and its ... Of Pavan Kumar Rati ... Need help on PHP for MPE/ix ...
    (comp.sys.hp.mpe)
  • Re: attempting to return values from array from w/in a function
    ... What I get is an array w/ only the most recent array entry. ... I am new to PHP & do not have formal scripting ... you end up comparing strings, but the test you mean probably is simply: ... case 1: {codeblock} ...
    (comp.lang.php)
  • Re: Advice about fetching user information
    ... but actually *selecting* them in MySQL ... PHP scripts and use a gaugefunction to time pretty much every ... The same is pretty much true for searching an array in PHP - ... But I wouldn't be searching. ...
    (comp.lang.php)