Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Array.length for a two dimensional array (y axis)

I am trying to use a function whereby I see how tall (y axis) a two dimensional array is in PHP. How would you suggest that I do this? Sorry, I am new to PHP.

like image 369
Spencer Avatar asked Mar 08 '11 20:03

Spencer


2 Answers

max(array_map('count', $array2d))
like image 180
phihag Avatar answered Oct 12 '22 23:10

phihag


A multi-dimensional array is simply an array of arrays -- it's not like you've blocked out a rectangular set of addresses; more like a train where each car can be stacked as high as you like.

As such, the "height" of the array, presumably, is the count of the currently largest array member. @phihag has given a great way to get that (max(array_map(count, $array2d))) but I just want to be sure you understand what it means. The max height of the various arrays within the parent array has no effect on the size or capacity of any given array member.

like image 27
Jacob Mattison Avatar answered Oct 13 '22 01:10

Jacob Mattison