,

Retrieve Total Number of Elements in an array php

PHP code tutorial

Sometimes you may need to know how many elements an array is containing.

For example, you got result from a mysql query in an array. Now you want to show total number of results returned by the query.

There’s a function in php called count() which can do it for you very easily. Use the following in your favourite code editor:

<?php 
      $my_array = array("value1", "value2", "value3", "value4");
      echo count($myarray);
 ?>

It will return 4. 

Abdul Awal Uzzal
Written byAbdul Awal Uzzal

Tech entrepreneur and AI-first founder. I lead the team behind ThemeNcode, TNCFlow and TNC FlipBook.

Get in touch