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

2010-03-17 Thread Richard Quadling
On 17 March 2010 01:10, Robert Cummings rob...@interjinn.com 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

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

2010-03-16 Thread Richard Quadling
On 15 March 2010 23:45, Daevid Vincent dae...@daevid.com wrote: Anyone have a function that will return an integer of the number of dimensions an array has? /** * Get the maximum depth of an array * * @param array $Data A reference to the data array * @return int The maximum number of

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

2010-03-16 Thread Robert Cummings
Richard Quadling wrote: On 15 March 2010 23:45, Daevid Vincent dae...@daevid.com wrote: Anyone have a function that will return an integer of the number of dimensions an array has? /** * Get the maximum depth of an array * * @param array $Data A reference to the data array * @return int

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

2010-03-16 Thread Peter Lind
This is one example where references actually decrease memory usage. The main reason is the recursive nature of the function. Try ?php echo memory_get_usage() . PHP_EOL; $array = range(0,100); $array[10] = range(0,10); $array[20] = range(0,10); $array[30] = range(0,10); $array[40] =

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

2010-03-16 Thread Robert Cummings
Peter Lind wrote: This is one example where references actually decrease memory usage. The main reason is the recursive nature of the function. Try ?php echo memory_get_usage() . PHP_EOL; $array = range(0,100); $array[10] = range(0,10); $array[20] = range(0,10); $array[30] = range(0,10);

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

2010-03-16 Thread Robert Cummings
Peter Lind wrote: This is one example where references actually decrease memory usage. The main reason is the recursive nature of the function. Try BTW, it's not the recursive nature of the function causing the problem. It's the movement of the internal pointer within the array. When it

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

2010-03-16 Thread Peter Lind
Hmm, will probably have to look inside PHP for this ... the foreach loop will copy each element as it loops over it (without actually copying, obviously), however there's no change happening to the element at any point and so there's nothing to suggest to the copy-on-write to create a new instance

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

2010-03-16 Thread Robert Cummings
Peter Lind wrote: Hmm, will probably have to look inside PHP for this ... the foreach loop will copy each element as it loops over it (without actually copying, obviously), however there's no change happening to the element at any point and so there's nothing to suggest to the copy-on-write to

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

2010-03-16 Thread Rene Veerman
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;

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

2010-03-16 Thread Robert Cummings
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) {

[PHP] Need routine to tell me number of dimensions in array.

2010-03-15 Thread Daevid Vincent
Anyone have a function that will return an integer of the number of dimensions an array has? I did some quick searches and came up with nothing. The closest was here of someone asking the same thing, but his solution isn't right:

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

2010-03-15 Thread Ashley Sheridan
On Mon, 2010-03-15 at 16:45 -0700, Daevid Vincent wrote: Anyone have a function that will return an integer of the number of dimensions an array has? I did some quick searches and came up with nothing. The closest was here of someone asking the same thing, but his solution isn't right:

RE: [PHP] Need routine to tell me number of dimensions in array.

2010-03-15 Thread Daevid Vincent
Oh. I know it's not a simple solution to do right Ashley. And exacerbated by the fact that each array dimension can have different dimensions as well. This is why I wanted someone else's solution first before I spend hours or days on one that works reliably. :) _ From: Ashley Sheridan

RE: [PHP] Need routine to tell me number of dimensions in array.

2010-03-15 Thread Ashley Sheridan
On Mon, 2010-03-15 at 17:23 -0700, Daevid Vincent wrote: Oh. I know it's not a simple solution to do right Ashley. And exacerbated by the fact that each array dimension can have different dimensions as well. This is why I wanted someone else's solution first before I spend hours or days on

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

2010-03-15 Thread Jim Lucas
Daevid Vincent wrote: Anyone have a function that will return an integer of the number of dimensions an array has? I did some quick searches and came up with nothing. The closest was here of someone asking the same thing, but his solution isn't right:

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

2010-03-15 Thread Robert Cummings
Jim Lucas wrote: Daevid Vincent wrote: Anyone have a function that will return an integer of the number of dimensions an array has? I did some quick searches and came up with nothing. The closest was here of someone asking the same thing, but his solution isn't right: