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
🌐
GeeksforGeeks
geeksforgeeks.org › php › what-is-the-difference-between-count-and-sizeof-functions-in-php
What is the difference between count() and sizeof() functions in PHP ? - GeeksforGeeks
July 23, 2025 - Array ( [Java] => Array ( [0] => ... an array: 3 All elements of an array: 7 · In conclusion, there is no difference between the count() and sizeof() methods of PHP....
🌐
PHP
php.net › manual › en › function.sizeof.php
PHP: sizeof - Manual
I would recommend not using sizeof(). Many programmers expect sizeof() to return the amount of memory allocated. Instead sizeof() -as described above- is an alias for count().
🌐
Medium
medium.com › @jochelle.mendonca › exploring-php-count-vs-sizeof-unveiling-the-differences-a87ca9d57660
xploring PHP: Count vs. Sizeof — Unveiling the Differences | Medium
January 3, 2024 - Whether you opt for count() because it's more widely used or sizeof() because it sounds cooler, you're in good hands. So, the next time you find yourself pondering which to use, remember they are two peas in a pod, aliases dancing harmoniously in the PHP realm.
🌐
php.cn
m.php.cn › home › backend development › php problem › what is the difference between php sizeof and count
What is the difference between php sizeof and count-PHP Problem-php.cn
September 23, 2021 - There is no difference between php sizeof() and count(). The sizeof() function is an alias of the count() function, which means that the function and usage of the sizeof() function are exactly the same as the count() function, and both can be ...
🌐
DevOps
devopstrainer.in › home › what is the difference between count or sizeof function in php? explain with example
What is the difference between count or sizeof function in PHP? explain with example - DevOps | SRE | DevSecOps
November 1, 2022 - "<br>"; echo "All elements of an array: " . sizeof($arr, 1); ?> ... Array ( [Javascript] => Array ( [0] => C++ [1] => Github ) [Selenium] => Array ( [0] => Ruby ) [PHP] => Array ( [0] => CodeLobster ) ) Sub elements of an array: 3 All elements of an array: 7 · count() function: The count() function is used to calculate all the elements in the array or any other countable object.
🌐
W3Schools
w3schools.com › php › func_array_sizeof.asp
PHP sizeof() Function
<?php $cars=array ( "Volvo"=>array ( "XC60", "XC90" ), "BMW"=>array ( "X3", "X5" ), "Toyota"=>array ( "Highlander" ) ); echo "Normal count: " . sizeof($cars)."<br>"; echo "Recursive count: " . sizeof($cars,1); ?> Try it Yourself » ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
Find elsewhere
🌐
Reintech
reintech.io › blog › comprehensive-guide-php-count-sizeof-functions
A Comprehensive Guide to PHP's `count()` and `sizeof()` Functions
Determining array size is a fundamental operation in PHP development. Whether you're validating user input, implementing pagination, or processing data structures, you need reliable methods to count elements. PHP provides two functions for this purpose: count() and sizeof().
🌐
TutorialsPoint
tutorialspoint.com › sizeof-function-in-php
PHP - Function sizeof()
December 23, 2019 - Python TechnologiesDatabasesComputer ProgrammingWeb DevelopmentJava TechnologiesComputer ScienceMobile DevelopmentBig Data & AnalyticsMicrosoft TechnologiesDevOpsLatest TechnologiesMachine LearningDigital MarketingSoftware QualityManagement Tutorials View All Categories ... Count elements in an array, or properties in an object. If the optional mode parameter is set to COUNT_RECURSIVE (or 1), sizeof() will recursively count 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 - Although sizeof() can be used for getting the length of an array, it’s recommended to use count() for clarity and consistency in your code. For multi-dimensional arrays, the count() function can be extended to count elements recursively using the COUNT_RECURSIVE mode.
🌐
Paulsprogrammingnotes
paulsprogrammingnotes.com › 2012 › 10 › sizeof-vs-count-in-php.html
Sizeof() vs Count() in PHP · Paul's Programming Notes
October 22, 2012 - http://php.net/manual/en/function.sizeof.phpThey’re the same. According to the link above: the sizeof function is an alias of: count()
🌐
Svachon
svachon.com › blog › benchmark-php-strlen-vs-count
Benchmark: PHP strlen vs. count (and sizeof) • Steven Vachon's Blog
March 25, 2012 - For the sake of search engines, I included sizeof() in the title. There was no need to include it in the benchmark as it’s the same as count() and runs at the same speed. ... <?php $test_array = array(0,1,2,3,4,5); $test_string = '/test/'; function getmicrotime() { list($usec, $sec) = explode(' ',microtime()); return ((float)$usec + (float)$sec); } $time_start = getmicrotime(); for ($i=0; $i<1000000; $i++) { count($test_array); } echo 'count() :: '.number_format(getmicrotime()-$time_start,3).' seconds<br/>'; $time_start = getmicrotime(); for ($i=0; $i<1000000; $i++) { strlen($test_string); } echo 'strlen() :: '.number_format(getmicrotime()-$time_start,3).' seconds<br/>';
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-sizeof-function
PHP sizeof() Function - GeeksforGeeks
December 2, 2021 - In this article, we will see how to get the length of the array using the sizeof() function in PHP. The sizeof() function is a built-in function in PHP and is used to count the number of elements present in an array or any other countable object.
🌐
DEV Community
dev.to › techyhunger › calculate-php-array-length-2elb
Array Length PHP: Calculate PHP Array Length - DEV Community
August 21, 2019 - And, when we use count function in the NORMAL mode as a second argument or default mode, Output is 2. sizeof() is an alias of PHP count() function and accepts the same arguments as count().
🌐
Toolsandtuts
toolsandtuts.com › home › how to get array length in php?
PHP Count VS sizeof? How to Get the Array Length in PHP?
September 20, 2024 - As per PHP official documentation, there is no difference between the count and sizeof functions.
🌐
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 - Consistency and Readability: The primary reason to favor count() over sizeof() is consistency. Most PHP developers are familiar with the count() function, making your code more readable and easier to understand for others.
🌐
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
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); ?>
🌐
ZetCode
zetcode.com › php-array › sizeof
PHP sizeof - Array Size in PHP
March 13, 2025 - The PHP sizeof function returns the number of elements in an array. It's an alias of count and works identically.