I would use count() if they are the same, as in my experience it is more common, and therefore will cause less developers reading your code to say "sizeof(), what is that?" and having to consult the documentation.

I think it means sizeof() does not work like it does in C (calculating the size of a datatype). It probably made this mention explicitly because PHP is written in C, and provides a lot of identically named wrappers for C functions (strlen(), printf(), etc)

Answer from alex on Stack Overflow
🌐
PHP
php.net › manual › en › function.count.php
PHP: count - Manual
// $limit is set to the number ... function count_recursive ($array, $limit) { $count = 0; foreach ($array as $id => $_array) { if (is_array ($_array) && $limit > 0) { $count += count_recursive ($_array, $limit - 1); } else { $count += 1; } } return $count; } ...
🌐
W3Schools
w3schools.com › php › func_array_count.asp
PHP count() Function
<?php $cars=array ( "Volvo"=>array ( "XC60", "XC90" ), "BMW"=>array ( "X3", "X5" ), "Toyota"=>array ( "Highlander" ) ); echo "Normal count: " . count($cars)."<br>"; echo "Recursive count: " .
People also ask

How do you count the number of keys in a PHP array?
The number of keys in a simple (one-dimensional) array is always equal to the number of elements. Therefore, using count() on the array gives you both the element count and the key count. The array_keys() function can return an array of all the keys, and you could then find the php array length of that new array, but simply using count() on the original array is far more direct and efficient.
🌐
upgrad.com
upgrad.com › home › blog › software development › php array length: a complete guide to finding array length in php [with examples]
PHP Array Length: Easy Methods to Find Array Size in PHP
What is the primary function to get the PHP array length?
The primary and most recommended function to get the php array length is count(). This built-in function is specifically designed to count all the elements in an array or the properties in an object. It is straightforward, efficient, and universally understood by PHP developers. When you need to determine the number of items in any array, count() should be your first choice.  Code Example:PHP$fruits = ["Apple", "Banana", "Cherry"];$length = count($fruits);// $length is now 3
🌐
upgrad.com
upgrad.com › home › blog › software development › php array length: a complete guide to finding array length in php [with examples]
PHP Array Length: Easy Methods to Find Array Size in PHP
How do I properly use the PHP array length in a for loop?
A for loop is a common use case for the php array length. You typically initialize the loop counter at 0 and have it continue as long as the counter is less than the array's length. The length is retrieved once using count() before the loop starts for optimal performance.Code Example:PHP$colors = ["Red", "Green", "Blue"];$length = count($colors);for ($i = 0; $i < $length; $i++) {   echo $colors[$i] . "
";}
🌐
upgrad.com
upgrad.com › home › blog › software development › php array length: a complete guide to finding array length in php [with examples]
PHP Array Length: Easy Methods to Find Array Size in PHP
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-count-all-array-elements-in-php
How to count all array elements in PHP ? - GeeksforGeeks
July 15, 2025 - To count all array elements in PHP using a loop, initialize a counter variable to zero. Iterate through the array elements using a loop and increment the counter for each element.
🌐
ReqBin
reqbin.com › code › php › iawpnvuz › php-array-length-example
How to get the length of an array in PHP?
May 24, 2023 - Additionally, PHP provides a wide ... an string, and converting an array into JSON. You can use the count() function to count the length of the specified array....
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-count-function
PHP count() Function - GeeksforGeeks
April 9, 2025 - The count() function in PHP is used to count the number of elements in an array or the countable properties of an object.
Find elsewhere
🌐
Medium
medium.com › @ok4304571 › php-array-count-function-f35e3c0f0843
PHP Array count() Function - Ok - Medium
June 13, 2025 - This function was introduced in PHP 4.0. int count ( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] );
🌐
Upgrad
upgrad.com › home › blog › software development › php array length: a complete guide to finding array length in php [with examples]
PHP Array Length: Easy Methods to Find Array Size in PHP
3 weeks ago - It checks whether the array is ... uncertain or dynamically populated datasets. The count() function provides a numeric evaluation of the number of elements present in the array....
🌐
Carmatec
carmatec.com › home › how to get the length of an array in php: complete guide
How to Get the Length of an Array in PHP: Complete Guide
September 28, 2024 - C The length of the array is: 5 In this example, the count() function returns the total number of elements in the array, which is 5. The sizeof() function is an alias of count() in PHP.
🌐
W3Schools
w3schools.com › Php › func_array_count_values.asp
PHP array_count_values() Function
Arrays Indexed Arrays Associative Arrays Create Arrays Access Array Items Update Array Items Add Array Items Remove Array Items Sorting Arrays Multidimensional Arrays Array Functions PHP Superglobals
🌐
CodeSignal
codesignal.com › learn › courses › php-associative-arrays-in-practice-revision-and-application › lessons › efficient-element-counting-with-associative-arrays-in-php
Efficient Element Counting with Associative Arrays in PHP
When the above PHP code executes, it displays the counts for each color: ... We began with an empty associative array. Then, we went through our list, and for every occurring element, we simply incremented its value in the associative array.
🌐
W3Schools
w3schools.sinsixx.com › php › func_array_count.asp.htm
PHP count() Function
Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › php tutorial › php array length
PHP array length | How does array length Work in PHP with Examples
April 18, 2023 - No of the search elements returned. Calculating average values in an array. But in PHP, to get the number of elements in an array, either sizeof or count function is enabled here to predict the array length in PHP.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-count-all-elements-in-an-array-in-php.php
How to Count All Elements or Values in an Array in PHP
PHP Array Functions PHP String ... PHP Filters PHP Error Levels ... You can simply use the PHP count() or sizeof() function to get the number of elements or values in an array....
🌐
FlatCoding
flatcoding.com › home › how to use php count() to get array length
How to Use PHP count() to Get Array Length - FlatCoding
June 22, 2025 - For example: $var = null; echo is_countable($var) ? count($var) : 0; If the value of $var is countable, it assigns its count; otherwise, it assigns zero. ... Here the count() gives 3 because the array holds three values.
🌐
Pi My Life Up
pimylifeup.com › home › how to get the length of an array in php
How to get the length of an Array in PHP - Pi My Life Up
October 1, 2022 - However, by setting the second parameter of the count() function to “COUNT_RECURSIVE“, we can get the length of the entire multi-dimensional array. ... For the first example, let us show you what happens when you get the array length in ...
🌐
Uc
journals.uc.edu › plugins › generic › pdfJsViewer › pdf.js › web › viewer.html
PDF.js viewer
Thumbnails · Document Outline · Attachments · Layers · Previous · Highlight all · Match case · Whole words · Presentation Mode · Print
🌐
Scaler
scaler.com › home › topics › how to find the length of an array in php?
How to Find the Length of an Array in PHP? - Scaler Topics
April 12, 2024 - In PHP, obtaining the size or length of an array is accomplished using the count() function. This function efficiently calculates and returns the total number of elements within an array, regardless of their data types.