How to get Array Size in Bytes in PHP

Knowing array size may be important during the validation. If we’re storing or retrieving some information in arrays, we should firstly check whether they’re not too big.

To get the array size in bytes, use the mb_strlen() and serialize functions.



$array = [5, 4, 3, 5, 4, 3, 5];
echo mb_strlen(serialize($array), '8bit');