🌐
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 » · ❮ PHP Array Reference · ★ +1 · Sign in to track progress · REMOVE ADS · PLUS · SPACES · GET CERTIFIED · FOR TEACHERS · BOOTCAMPS · CONTACT US · × · If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ·
🌐
Unibo
www-db.disi.unibo.it › courses › PAW › DOCS › w3schools › php › func_array_sizeof.asp.html
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); ?> Run example » ... Color Converter Google Maps Animated Buttons Modal Boxes Modal Images Tooltips Loaders JS Animations Progress Bars Dropdowns Slideshow Side Navigation HTML Includes Color Palettes Code Coloring ... Your message has been sent to W3Schools.
People also ask

Are sizeof() and count() the same function in PHP?
Yes, sizeof() and count() are functionally identical. sizeof() is simply an alias of count(), meaning they do the exact same thing and can be used interchangeably. Both functions help you find length of an array in php. However, for the sake of consistency and clarity, the official PHP documentation and community best practices recommend using count() to avoid confusion with the sizeof operator in other languages like C, where it relates to memory size.
🌐
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
What is the difference between count() and strlen() in PHP?
These functions serve completely different purposes. count() is used to find length of an array in php by counting the number of elements it contains. strlen(), on the other hand, is used to find the length of a string by counting the number of bytes it occupies (not necessarily the number of characters for multi-byte encodings). Using strlen() on an array will not give you the php array length and will likely result in an error or unexpected behavior.
🌐
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
🌐
W3Schools
w3schools.sinsixx.com › php › func_array_sizeof.asp.htm
PHP sizeof() Function - SinSiXX - W3Schools
Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building.
🌐
PHP
php.net › manual › en › function.sizeof.php
PHP: sizeof - Manual
Instead sizeof() -as described above- is an alias for count(). Prevent misinterpretation and use count() instead. ... If your array is "huge" It is reccomended to set a variable first for this case: THIS-> $max = sizeof($huge_array); for($i ...
🌐
W3Schools
w3schools.sinsixx.com › php › func_array_sizeof.asp@output=print.htm
PHP sizeof() Function - W3Schools
From http://www.w3schools.com (Copyright Refsnes Data) Complete PHP Array Reference · The sizeof() function counts the elements of an array, or the properties of an object. This function is an alias of the count() function. Note: This function may return 0 if a variable isn't set, but it may ...
🌐
W3schoolsapp
w3schools.w3schoolsapp.com › php › func_array_sizeof.html
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 » · ❮ PHP Array Reference · Tabs Dropdowns Accordions Side Navigation Top Navigation Modal Boxes Progress Bars Parallax Login Form HTML Includes Google Maps Range Sliders Tooltips Slideshow Filter List Sort List · × · If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail: help@w3schools.com ·
🌐
W3Schools
w3schools.am › php › func_array_sizeof.html
PHP sizeof() Function - W3Schools.am
sizeof($cars)."<br>"; echo "Recursive count: " . sizeof($cars,1); ?> Try it Yourself » · ❮ PHP Array Reference · Tabs Dropdowns Accordions Side Navigation Top Navigation Modal Boxes Progress Bars Parallax Login Form HTML Includes Google Maps Range Sliders Tooltips Slideshow Filter List Sort List ·
🌐
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 - Let’s explore these methods in detail to effectively manage array length in PHP. The sizeof() function is an alias for count() and is used to determine the number of elements in an array.
Find elsewhere
🌐
W3Schools
w3schools.com › c › c_arrays_size.php
C Get the Size of an Array
The sizeof formula works for arrays of any type and any size: double myValues[] = {1.1, 2.2, 3.3}; int length = sizeof(myValues) / sizeof(myValues[0]); printf("%d", length); // Prints 3 · Try it Yourself » · In the next chapter, you will ...
🌐
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.
🌐
ZetCode
zetcode.com › php-array › sizeof
PHP sizeof - Array Size in PHP
March 13, 2025 - Syntax: sizeof(array|Countable $value, int $mode = COUNT_NORMAL): int. The optional mode parameter can be COUNT_RECURSIVE for multidimensional arrays. This demonstrates counting elements in a simple indexed array. ... <?php $fruits = ['apple', 'banana', 'orange']; $count = sizeof($fruits); ...
🌐
freeCodeCamp
freecodecamp.org › news › php-array-length-how-to-get-an-array-size
PHP Array Length Tutorial – How to Get an Array Size
August 27, 2021 - However, sizeof() is just an alias of count(), and many folks assume (rightly so) that sizeof() would return the memory usage of an array. Therefore it's better to stick with count(), which is a much more suitable name for what you are doing – counting elements in an array. Thanks for reading! I hope you now have a better understanding of how to find the size of an array in PHP.
🌐
TutorialKart
tutorialkart.com › php › php-sizeof
PHP Array sizeof() - Size of Array
May 7, 2023 - In this example, we will take an nested arrays, and find the number of elements in it recursively using sizeof() function. ... <?php $array1 = array("apple","banana", array(12, 14, 17), array("a", "b", "c", "d"), ); $result = sizeof($array1, COUNT_RECURSIVE); echo $result; ?>
🌐
Jobtensor
jobtensor.com › Tutorial › PHP › en › Array-Functions-sizeof
PHP Built-in sizeof(), Definition, Syntax, Parameters, Examples | jobtensor
The sizeof() function count all elements in an array (alias of count() function). ... <?php // Example 1 $cities = array("New York", "London", "Tokyo", "Berlin", "Cairo"); echo sizeof($cities) . "<br>"; // Example 2 $persons = array( "Mark" => array(22, "USA"), "Jeff" => array(32, "JPN"), "Mike" ...
🌐
ReqBin
reqbin.com › code › php › iawpnvuz › php-array-length-example
How to get the length of an array in PHP?
To get the array's length in PHP, you can use the count() and sizeof() functions that return the number of items in the array. Function sizeof() is the alias of the count() function.
🌐
W3Schools
w3schools.com › c › c_data_types_sizeof.php
C sizeof operator
Which means if you have an array of 1000 char values, it will occupy 1000 bytes (1 KB) of memory. Using the right data type for the right purpose will save memory and improve the performance of your program. You will learn more about the sizeof operator later in this tutorial, and how to use it in different scenarios.
🌐
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 - While sizeof() might be available in most versions, there's no guarantee it will always be maintained or have consistent behavior. In contrast, count() is a more widely adopted and well-supported function, ensuring better cross-version compatibility and minimizing potential issues when migrating code. Community Best Practices: The PHP community convention has established count() as the preferred method for calculating array sizes.
🌐
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 - <!DOCTYPE html> <html> <body> <?php $bike=array ( "Hero Splender"=>array ( "HP2345", "HS3456" ), "Royal Enfield"=>array ( "R3", "Tr5" ), "Honda Activa 6G"=>array ( "Classic 250" ) ); echo "General count: " . sizeof($bike)."<br>"; echo "Recursive Number: " .
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai