Instance
Returns the and (5+15+25) of all values in the array:
<?php$a=array (5,15,25); Echo array_sum ($a);? >
Definition and usage
The Array_sum () function returns the and of all values in the array.
Grammar
Array_sum (Array)
Parameters |
Describe |
Array |
Necessary. Specifies the array. |
technical details
return value: |
Returns the and of all values in the array. |
php version: |
4.0.4+ |
update log: |
php 4.2.1 modified the incoming array itself to convert the string values into numeric values (which in most cases were converted to 0, depending on the value). |
More examples
Example 1
Returns the and (52.2+13.7+0.9) of all values in the array:
<?php$a=array ("A" =>52.2, "B" =>13.7, "C" =>0.9); Echo array_sum ($a);? >
Example 1
<?php $a =array (0=> "5",1=> ",2=>" 25 "); echo array_sum ($a);?>
Output:
45
Example 2
<?php $a =array (0=>5,1=>15,2=>25); echo array_sum ($a);?>
Output:
45
Example 3
<?php $a =array (0=>5,1=>15.5,2=>25); echo array_sum ($a);?>
Output:
45.5
Example 4
<?php $a =array (0=>5,1=> "15s", 2=>25); echo array_sum ($a);?>
Output:
45
Example 5
<?php $a =array (0=>5,1=> "s15s", 2=>25); echo array_sum ($a);?>
Output:
30