๐ŸŒ
GitHub
gist.github.com โ€บ kirilkirkov โ€บ 0444d3fd95ef30facac3
Return a size in bytes,kilobytes,megabytes and gigabytes for given array or string. Can be used if you want to check performance for some script. ยท GitHub
Return a size in bytes,kilobytes,megabytes and gigabytes for given array or string. Can be used if you want to check performance for some script. - array_in_lenght
Discussions

memory - Is there a way I get the size of a PHP variable in bytes? - Stack Overflow
I currently have a PHP CLI script using Zend Framework extensively which seems to be using a ever larger amount of memory as it runs. It loops through a large set of models retrieved from a databas... More on stackoverflow.com
๐ŸŒ stackoverflow.com
caching - PHP: Measure size in kilobytes of a object/array? - Stack Overflow
What's an appropriate way of measure a PHP objects actual size in bytes/kilobytes? Reason for asking: I am utilizing memcached for cache storage in my web application that will be used by non-techn... More on stackoverflow.com
๐ŸŒ stackoverflow.com
August 14, 2014
size (in KB) of variable in php - Stack Overflow
is it possible to calculate / estimate the size (in KB) of a variable (string, array but mostly array). What happen is that we store some data inside memcache, and we would like to know how much me... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Size of an array in memory in php - Stack Overflow
I am trying to figure out the size of a variable in php. The reason i need to do this is because if it is over 1mb i need to use a different form of caching rather than memcache as memcache has a ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
PHPBuilder
board.phpbuilder.com โ€บ d โ€บ 10305084-the-size-of-arrays-in-bytes
The size of arrays, in bytes... - PHPBuilder Forums
July 23, 2005 - I have a large array of almost 1200 indices. Each one is a string, and they vary widely in length. During my script's execution most of them are not needed,...
๐ŸŒ
GitHub
github.com โ€บ mrsuh โ€บ php-var-sizeof
GitHub - mrsuh/php-var-sizeof: Function for getting size of any PHP variable in bytes ยท GitHub
'/vendor/autoload.php'; $int = 1; printf("variable \$int size: %d bytes\n", var_sizeof($int)); $array = array_fill(0, 100, $a); printf("variable \$array size: %d bytes\n", var_sizeof($array)); $object = new \stdClass(); printf("variable \$object size: %d bytes\n", var_sizeof($object)); printf("class \$object size: %d bytes\n", var_class_sizeof($object));
Author ย  mrsuh
๐ŸŒ
Npopov
npopov.com โ€บ 2011 โ€บ 12 โ€บ 12 โ€บ How-big-are-PHP-arrays-really-Hint-BIG.html
How big are PHP arrays (and values) really? (Hint: BIG!)
December 12, 2011 - As you can see one needs to store ... that sure needs much info). The sizes of the individual components are 8 bytes for the unsigned long, 4 bytes for the unsigned int and 7 times 8 bytes for the pointers....
๐ŸŒ
Quora
quora.com โ€บ How-can-I-get-the-byte-size-of-a-variable-in-PHP
How to get the byte size of a variable in PHP - Quora
Answer (1 of 2): Depends on the type of variable. For strings for example you can use strlen, since PHP uses the C version of strlen internally which counts bytes (one of the reasons why iconv_strlen exists). Everything else you can do hack type things like using strlen on a serialization of an...
๐ŸŒ
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(). 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 = 0; $i < $max;$i++) { code...
Find elsewhere
๐ŸŒ
Mrsuh
mrsuh.com โ€บ projects โ€บ php-var-sizeof
PHP var_sizeof()
They calculate the size of internal structures like zval, _zend_array, _zend_object, etc., along with any additional allocated memory for these structures. However, they do not account for the memory used by handlers, functions, or similar components. ... <?php require_once __DIR__ . '/vendor/autoload.php'; $int = 1; printf("variable \$int size: %d bytes\n", var_sizeof($int)); $array = array_fill(0, 100, $a); printf("variable \$array size: %d bytes\n", var_sizeof($array)); $object = new \stdClass(); printf("variable \$object size: %d bytes\n", var_sizeof($object)); printf("class \$object size: %d bytes\n", var_class_sizeof($object));
๐ŸŒ
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 - 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 ...
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ func_array_sizeof.asp
PHP sizeof() Function
The sizeof() function is an alias of the count() function. ... <?php $cars=array ( "Volvo"=>array ( "XC60", "XC90" ), "BMW"=>array ( "X3", "X5" ), "Toyota"=>array ( "Highlander" ) ); echo "Normal count: " . sizeof($cars)."<br>"; echo "Recursive ...
๐ŸŒ
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 - There are two common ways to get the size of an array. The most popular way is to use the PHP count() function. As the function name says, count() will return a count of the elements of an array.
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ blog โ€บ data science โ€บ how to find array length in php?
How to find Array Length in PHP? | upGrad blog
June 8, 2026 - But it is wiser to stick to the count() function since other programmers may expect the sizeof() function to return the size of a particular array in bytes or memory. There is technically no maximum limit for an array.
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_arrays_size.php
C Get the Size of an Array
You learned from the Data Types chapter that an int type is usually 4 bytes, so from the example above, 4 x 5 (4 bytes x 5 elements) = 20 bytes. Knowing the memory size of an array is great when you are working with larger programs that require good memory management.
๐ŸŒ
freebasic.net
freebasic.net โ€บ board index โ€บ programming โ€บ general
[solved]How to get the size of array items in bytes ? - freebasic.net
#macro GET_DIMENSION(_array,_dimension,_temp) function _temp(array() as typeof(_array)) as integer Dim _d As Integer Asm mov esi, [ebp+8] mov eax, [esi+16] mov [_d], eax End Asm return _d end function _dimension= _temp(_array()) #endmacro #macro GetSize(array,temp,d) GET_DIMENSION(array,d,temp) print "----------------------------" print "Array is:" for n as integer=1 to d if n=1 then d=1 print lbound(array,n);" to";ubound(array,n);","; d=d*(ubound(array,n)-lbound(array,n)+1) next d=d*sizeof(array) print #endmacro '=============================================== dim as integer Size dim as doubl
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ getting-size-in-memory-of-an-object-in-php
Getting size in memory of an object in PHP?
March 15, 2026 - Object memory size: 440 bytes Current memory usage: 2097720 bytes ยท For more accurate results, use the real_usage parameter to get actual memory allocated by the system โˆ’ ยท <?php class DataClass { public $name; public $values = array(); public function __construct($name) { $this->name = $name; for ($i = 0; $i < 100; $i++) { $this->values[] = rand(1, 1000); } } } function measureObjectSize($className, ...$args) { $before = memory_get_usage(true); $obj = new $className(...$args); $after = memory_get_usage(true); return array( 'object' => $obj, 'size' => ($after - $before) ); } $result = measureObjectSize('DataClass', 'TestObject'); echo "Object size (real memory): " .