Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get a single value from count()

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should count it after this loop

foreach ($studentlistbysection as $stlist) {
        $numstudent[] = $stlist->id;
    }
echo count($numstudent);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading