How to get total number of elements used in array in PHP ? Last Updated : 09 Oct, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to get total number of elements in PHP from an array. We can get total number of elements in an array by using count() and sizeof() functions. Using count() Function: The count() function is used to get the total number of elements in an array. Syntax: count(array) Parameters: It accepts a single parameter i.e. array which is the input array. Return Value: It returns the number of elements in an array. Program 1: PHP program to count elements in an array using count() function. PHP <?php // Create an associative array // with 5 subjects $array1 = array( 0 => 'php', 1 => 'java', 2 => 'css/html', 3 => 'python', 4 => 'c/c++' ); // Get total elements in array echo count( $array1); ?> Output5 sizeof() Function: The sizeof() function is used to count the number of elements present in an array or any other countable object. Syntax: sizeof(array) Parameters: It accepts only one parameter array which is the input array. Return Value: It returns the number of elements present in an array. Examples: Input: array(10,20,30,50) Output: 4 Input: array("Hello","geeks") Output: 2 Program 2: PHP program to count number of elements using sizeof() function. PHP <?php // Create an associative array // with 5 subjects $array1 = array( 0 => 'php', 1 =>'java', 2 => 'css/html', 3 => 'python', 4 => 'c/c++' ); // Get total elements in array echo sizeof( $array1); ?> Output5 Comment More infoAdvertise with us Next Article How to get total number of elements used in array in PHP ? S sravankumar_171fa07058 Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Questions Similar Reads How to find the Total Number of Elements in an Array in TypeScript ? In TypeScript, arrays are a common data structure used to store collections of elements. You can store multiple elements of different or the same data type inside them by explicitly typing. The below methods can be used to accomplish this task: Table of Content Using the length property Using the fo 3 min read How to get the number of lines in a file using PHP? Given a file reference, find the number of lines in this file using PHP. There are a total of 3 approaches to solve this. test.txt: This file is used for testing all the following PHP codes Geeks For Geeks Approach 1: Load the whole file into memory and then use the count() function to return the nu 2 min read How to find the index of an element in an array using PHP ? In this article, we will discuss how to find the index of an element in an array in PHP. Array indexing starts from 0 to n-1. Here we have some common approachesTable of ContentUsing array_search() FunctionUsing array_flip()Using a custom functionUsing a foreach LoopUsing array_keys FunctionUsing ar 6 min read Perl | Getting the Number of Elements of an Array An array in Perl is a variable used to store an ordered list of scalar values. An array variable is preceded by an "at" (@) sign. The size of an array can be determined using the scalar context on the array which returns the number of elements in the array Example 1: Perl #!/usr/bin/perl # Initializ 2 min read Find the Most Frequent Element in an Array in PHP Given an array, i.e. $arr, the task is to find the most frequent element in an array. There are multiple ways to solve this problem in PHP we will be going to discuss them. These problems can be used during data analysis, Web Analytics, or highly used in fraud detection. Example: Input: $array = [1, 2 min read Like