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

I am trying to use a function in which I see how a tall (y axis) two-dimensional array is in PHP. How do you suggest me to do this? Sorry, I'm new to PHP.

+5
source share
7 answers
max(array_map('count', $array2d))
+23
source

A multidimensional array is just an array of arrays - it doesn't look like you blocked a rectangular set of addresses; more like a train where each car can be stacked as high as you like.

, "" , -, . @phihag (max(array_map(count, $array2d))), , , . .

+3
$max = 0;

foreach($array as $val){
 $max = (count($val)>$max?count($val):$max)
}

$max - ,

+1

y , count($array). count($array[0]), .

+1

, count :

$counter = 0;
foreach($var AS $value) {
    $counter += count($value);
}

echo $counter;
0

1.dimension:

count($arr);

2.dimension:

function count2($arr) {
  $dim = 0;

  foreach ($arr as $v) {
    if (count($v) > $dim)
      $dim = count($v);
  }

  return $dim;
}

/ ( ), max. .

0

.

$array = array();

$array[0][0] = "one";
$array[0][1] = "two";

$array[1][0] = "three";
$array[1][1] = "four";

for ($i=0; isset($array[$i][1]); $i++) {
    echo $array[$i][1];
}

: twofour

, , .

0

All Articles