Re: Need routine to tell me number of dimensions in array.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 17 March 2010 01:10, Robert Cummings <robert@xxxxxxxxxxxxx> wrote:
>
> Rene Veerman wrote:
>>
>> maybe you should be foreach()ing with references?
>> php.net : search "foreach" :
>>
>>
>> As of PHP 5, you can easily modify array's elements by preceding
>> $value with &. This will assign reference instead of copying the
>> value.
>> <?php
>> $arr = array(1, 2, 3, 4);
>> foreach ($arr as &$value) {
>>    $value = $value * 2;
>> }
>> // $arr is now array(2, 4, 6, 8)
>> unset($value); // break the reference with the last element
>> ?>
>> This is possible only if iterated array can be referenced (i.e. is
>> variable),
>
> References in foreach don't work the way you think they work. You will still
> incur the copy. At least I did when I tested earlier today :)
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

The peak memory usage when using references (or not) and using
foreach() vs array_walk() was the same in all my testing.

But surprisingly, the foreach() with references all round used the
lowest memory during the looping. The worse case was mixing reference
and value passing with array_walk().

My dataset was generated by reading the C:\PHP5 directory where the
keys are the directories and saving the data as an include
(var_export()-ing it).

RIchard.
-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux