Skip to content

How to Count Array Elements in PHP

Category
PHP

You can use the PHP count() or sizeof() function to get the number of elements or values in an array. The count() and sizeof() method returns 0 for a variable that has been initialized with an empty array. If the array is not initialized, you will see an error. In that case, you can use the isset() function to check whether a variable is set or not.

Using sizeof():

Using count():

Rahul

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top