How to count elements inside array/object on PHP? -


i have array being sent view

array (     [0] => stdclass object         (             [emg_id] => 2             [fkit] => 1             [door] =>          )  ) 

i count how many elements empty, null, or '0'.

i tried using count returns '1', instead of counting of elements, can later determine satisfy conditions above.

any ideas i'm doing wrong?

// number of "null" elements echo count(array_filter((array) $array[0], 'is_null')); 

there other is_*()-functions built-in, may example count number of strings (and on).

to test, if element (e.g.) 0, suggest use anonymous function

echo count(array_filter((array) $array[0], function ($item) {   return $item === 0; })); 

the other cases similar.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -