Answer the question
In order to leave comments, you need to log in
How to count the number of elements in an array if specific ones are needed?
Hello!
So, there is a task, to count the number of elements in the array, while the count of elements should be exactly those whose height is greater than 173.
- I know how to count count($height);
- And how to set if conditions.
= But here's how to combine everything into one "composition", I'll never know, help pliz. =)
Answer the question
In order to leave comments, you need to log in
$array = ;
$filtered = array_filter($array, function ($item) {return $item['height'] >= 3;});
echo count($filtered);
And then count the result.
array_filter(
$array,
function($row) {
return $row['height'] > 173;
}
);
$scoolChild = array(
'Антон' => 172,
'Семен' => 165,
'Лена' => 189,
'Иван' => 171,
'Петр' => 182,
'Сидор' => 176,
'Аня' => 180,
'Таня' => 179,
'Маня' => 171
);
$tall = array_filter(
$scoolChild,
function($height) {
return $height > 173;
}
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question