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

(10-21-2016, 12:18 AM)salain Wrote: 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.


That worked fine thanks
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
RE: Work out a percentage of a item set in array - by wolfgang1983 - 10-21-2016, 01:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB