Answer the question
In order to leave comments, you need to log in
php. How to count separately the number of columns and rows of a two-dimensional array?
There is a filled array.
since the array is small, I can record the number of rows and columns myself. It is interesting to know how to tell the program to count the elements separately for rows and columns (instead of rows, columns in the loop).
$arr =array($ar1=array("рр","ыы","ыаы",20,"ыаы",2),
$ar2=array("ыпв","ып","вп",9,"впрр",4),
$ar3=array( "вр","вр","вр",30,"вр",5),
$ar4=array("врар","ароа","аоао",50,"ааоао",12));
$rows=4;
$columns=6;
for($i=0;$i<$rows;$i++)
{
for($j=0;$j<$columns;$j++)
{
Answer the question
In order to leave comments, you need to log in
$arr = [
["рр","ыы","ыаы",20,"ыаы",2],
["ыпв","ып","вп",9,"впрр",4],
[ "вр","вр","вр",30,"вр",5],
["врар","ароа","аоао",50,"ааоао",12]
];
for($i = 0; $i < count($arr); $i++)
{
for($j = 0; $j < count($arr[$i]); $j++)
{
}
}
You can simply calculate the number like this:
$count = 0;
$data = [
['a', 'b', 'c'],
['d', 'd', 'e'],
['f', 'h', 'j']
];
foreach ($data as $datum) {
$count += count($datum);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question