7

How to count all elements or values in an array in PHP

 1 year ago
source link: https://www.laravelcode.com/post/how-to-count-all-elements-or-values-in-an-array-in-php
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to count all elements or values in an array in PHP

  1701 views

  2 years ago

PHP

Use the PHP count() or sizeof() function

You can simply use the PHP count() or sizeof() function to get the number of elements or values in an array. The count() and sizeof() function returns 0 for a variable that has been initialized with an empty array, but it may also return 0 for a variable that isn't set.

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

<?php
$days = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
 
// Printing array size
echo count($days);
echo "<br>";
echo sizeof($days);
?>
Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK