Re: Re: Array sizes?
| From: | Anders Norrbring | Date: | Wed, 08 Feb 2006 19:17:00 +0000 |
| Subject: | Re: Re: Array sizes? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-230122@lists.php.net to get a copy of this message | ||
Rory Browne skrev:
Exactly what I was looking for.. :) Thanks! I personally don't need this at runtime, only at design time, just to help setting limits etc for the running app when testing. -- Anders Norrbring Norrbring ConsultingAt 01:05 AM 2/8/2006, Barry wrote:the problem I would have with the above code would be that it assumes you're using a single dimention array. Recursive foreach: function array_size($a){I don't think a "function" exists, but i would probably use (for benchmarking) a recursive foreach in combination with strlen. And add it all up. (This is probably some work for the PC so that's why benchmarking)It would be interesting to know whether that method was faster or slower than using this:$iLen = strlen(implode("", $aArray));$size = 0; while(list($k, $v) = each($a)){ $size += is_array($v) ? array_size($v) : strlen($v); } return $size;} This could possibly be optimised even more by using references or something like that. eg foreach(array_keys($a) as $k){size = is_array($a[$k]) =& array_size($a[$k]) : strlen($a[$k])But I think that for the most part your time programming will be more important than the programs time running.