Re: [nyphp-talk] Getting the number of dimensions of an array

2012-05-18 Thread Joey Derrico
I have test some of these out, but count(recursive) doesn't give the depth of an array Joey On Fri, May 18, 2012 at 5:11 PM, Anthony Ferrara wrote: > Except that doesn't do what you think it does... > > $a = [[[1,2]]]; > > The depth here is clearly 3. > > But count($a, COUNT_RECURSIVE); gives 4:

Re: [nyphp-talk] Getting the number of dimensions of an array

2012-05-18 Thread Anthony Ferrara
Except that doesn't do what you think it does... $a = [[[1,2]]]; The depth here is clearly 3. But count($a, COUNT_RECURSIVE); gives 4: http://codepad.viper-7.com/7xPYCu It counts the total number of elements in the array, and any child arrays (including the child array)... Also: constants exis

Re: [nyphp-talk] Getting the number of dimensions of an array

2012-05-18 Thread Chris Snyder
On Fri, May 18, 2012 at 5:03 PM, Donald Organ wrote: > http://us.php.net/count > > $size = count($array, 1); > Hah, nice. I love the warning: count() does not detect infinite recursion. ___ New York PHP User Group Community Talk Mailing List http://list

Re: [nyphp-talk] Getting the number of dimensions of an array

2012-05-18 Thread Donald Organ
http://us.php.net/count $size = count($array, 1); On Fri, May 18, 2012 at 4:54 PM, Anthony Ferrara wrote: > Another trick would be to not use function recursion, but a recursive > iterator: > > http://codepad.viper-7.com/9PeM9c > > function maxDepth(array $a) { >$it2 = new RecursiveItera

Re: [nyphp-talk] Getting the number of dimensions of an array

2012-05-18 Thread Anthony Ferrara
Another trick would be to not use function recursion, but a recursive iterator: http://codepad.viper-7.com/9PeM9c function maxDepth(array $a) { $it2 = new RecursiveIteratorIterator( new RecursiveArrayIterator($a) ); $max = 0; foreach ($it2 as $val)

Re: [nyphp-talk] Getting the number of dimensions of an array

2012-05-18 Thread justin
function array_depth($el) { return is_array($el) ? max(array_map('array_depth', $el)) + 1 : 0; } var_dump(array_depth($array)); -- justin On Fri, May 18, 2012 at 1:27 PM, Joey Derrico wrote: > I am trying to count the number of dimensions in an array. I used my > google-fu and came up wi

Re: [nyphp-talk] Getting the number of dimensions of an array

2012-05-18 Thread Federico Ulfo
Easy just use a recursive function as shown here: http://pt.php.net/manual/en/ref.array.php#49219 On Fri, May 18, 2012 at 4:27 PM, Joey Derrico wrote: > I am trying to count the number of dimensions in an array. I used my > google-fu and came up with answers that don't actually work because I ca

[nyphp-talk] Getting the number of dimensions of an array

2012-05-18 Thread Joey Derrico
I am trying to count the number of dimensions in an array. I used my google-fu and came up with answers that don't actually work because I can have multi-dimensional array's where one int he middle is multi and the one after not. Below is my latest set of test code (I have been playing with it for