I'm trying to get the number of ids in an array but my code outputs the count like an array instead of giving me a single value.
<?php
foreach ($studentlistbysection as $stlist) {
$numstudent[] = $stlist->id;
echo count($numstudent);
}
This outputs the number as 12345678910
instead of a single value like 10
How do I count the number of ids in my array?
CodePudding user response:
You should count it after this loop
foreach ($studentlistbysection as $stlist) {
$numstudent[] = $stlist->id;
}
echo count($numstudent);