how to get the nested array count with key values seperated in php -
this array
array ( [2] => array ( [0] => array ( [id] => 2 [res_id] => 1 [grand_total] => 303.42 [time] => 2016-07-28 11:04:38 [status] => 0 ) [1] => array ( [id] => 2 [res_id] => 1 [grand_total] => 303.42 [time] => 2016-07-28 11:04:38 [status] => 0 ) ) [1] => array ( [0] => array ( [id] => 1 [res_id] => 1 [grand_total] => 303.42 [time] => 2016-07-28 11:04:17 [status] => 0 ) ) )
from need sub array count i.e., array having 2 indexes such 2 & 1
2 & 1
there nested arrays found such 0 & 1
each
here,i need array count follows
array ( [2] => array ( [count] = 2 ) [1] => array ( [count] = 1 ) )
how should this..
someone me out of this...
thank you..
it easy foreach array , use count or sizeof function.
$desiredarray = array(); foreach ($myarray $key => $value) { $desiredarray [$key] ['count'] = sizeof ($value); } print_r ($desiredarray);
the output desired output
array ( [2] => array ( [count] = 2 ) [1] => array ( [count] = 1 ) )
Comments
Post a Comment