Define get_avg function
This function can give result with an array or argument, If need this code copy and defined it in your project library but don’t republish it anywhere share and comment or improvements suggestion for better code will be appreciated.
function get_avg($arrayORArgs){ if(is_array($arrayORArgs)){ return array_sum($arrayORArgs) / count($arrayORArgs); } else if(is_numeric($arrayORArgs)){ $func_info = debug_backtrace(); return array_sum($func_info[0]['args']) / count($func_info[0]['args']); } return 0; }
Call get_avg function with array argument.
The function return result 27.5 with array argument
$array_average = array(50,10,20,30); echo get_avg($array_average);
Call get_avg function with number arguments.
The function return result 27.5 with number arguments
echo get_avg(50,10,20,30);