Sum of elements of PHP array by using array_sum() and getting average value

preview_player
Показать описание

We can get the total values of all elements by suing array_sum() in PHP
We can sum all integers and float values in an array, if there are any string inside the array then same will be ignored.
We can find out the average value by using the total value and the number of elements. Function count() can be used to get the total number of elements in an array.
$ar=array(5,2,6,8,1);
echo "Total : ".array_sum($ar);

#phparraysum #phparraysumvalue #sumofelements
Рекомендации по теме