Welcome Guest, Not a member yet? Register   Sign In
[Solved] Work out a percentage of a item set in array
#2

Hi,

This should do it:


PHP Code:
$cnt_keys count($array); // 11 keys 
$cnt_values count(array_filter($array)); // 10 values 
$percent $cnt_values $cnt_keys 100// 90.9091 %
echo round($percent,2); 

Array_filter will only return non empty values.
If you need a more complex filter you can pass a function to array_filter as second parameter.
A good decision is based on knowledge and not on numbers. - Plato

Reply


Messages In This Thread
RE: Work out a percentage of a item set in array - by salain - 10-21-2016, 12:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB