Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php get array's data size

Tags:

arrays

php

size

Having this array:

Array
(
    [_block1] => Array
        (
            [list] => Array
            (
                 [sub-list] => Array
                 (
                 )
            )
            [links] => Number
            [total] => Number
            ...
        )
    [_block2] => Array
        (
             [@attributes] => Array
             (
             )
             [title] => ...
             [data] => Array ()
             ...
        )
    [_block3] => Array
        (
             ..
        )
)

Those blocks contain data returned by api. Knowing that each api returns data in a different way/structure I need to measure/calculate the data/size inside of each and one of them and then do if data > X or < do something.

Is it possible? I have searched google but I only found count() and that isn't what I need to make this work.

Edit: Each and of the those blocks contain many other sub blocks, and I was thinking of calculating the data size in bytes, because count wont do the job here.

like image 529
Alex Avatar asked Jan 26 '12 13:01

Alex


People also ask

How do you find the size of an array in PHP?

Answer: Use the PHP count() or sizeof() function You can simply use the PHP count() or sizeof() function to get the number of elements or values in an array. 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.

How do you find the size of an array?

We can find the size of an array using the sizeof() operator as shown: // Finds size of arr[] and stores in 'size' int size = sizeof(arr)/sizeof(arr[0]);

What is difference between count and sizeof in PHP?

1. The sizeof() function is used to return the number of elements in an array. The count() returns the number of elements in the array.

What is length of an array?

Basically, the length of an array is the total number of the elements which is contained by all the dimensions of that array. Syntax: public int Length { get; } Property Value: This property returns the total number of elements in all the dimensions of the Array.


1 Answers

echo  mb_strlen(serialize((array)$arr), '8bit');
like image 182
Masoud Rostami Avatar answered Oct 23 '22 00:10

Masoud Rostami