php

PHP – Count Array Elements

In this tutorial, we are going to see how to count all the elements of an array in PHP. You can use count() or sizeof() function to get the number of elements or values in an array. count() and sizeof() functions return 0 for an empty array, but can also return 0 for an undefined variable.

You can use the isset() function to check whether a variable is set or not.
 

Count Array Elements in PHP
<?php
	$langages = array("PHP", "Java", "Python", "HTML");
	 
	// Count array elements
	echo count($langages);
	echo "<br>";
	echo sizeof($langages);
?>

Output:

4
4

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

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