Example
Calculate and return the product of array:
<?php $a=array(5,5); echo(array_product($a)); ?>
Definition and usage
array_product() FunctionCalculation and returns the product of arrays.
Syntax
array_product(array)
Parameters | Description |
array | Required. Specifies an array. |
Technical details
Return value: | Returns the product of an integer or floating point number. |
PHP Version: | 5.1.0+ |
Change Log: | Since PHP 5.3.6, the product of empty arrays is 1. Prior to PHP 5.3.6, the product of empty arrays was 0. |
More examples
Example 1
Calculate and return the product of arrays:
<?php $a=array(5,5,2,10); echo(array_product($a)); ?>
Example 1 (Pure Numbers (array without string ):
<?php $arr=array(2,3,4); echo array_product($arr); ?>
Output result: 24
Example (array containing string):
<!doctype html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="Content-Type" content="text/hmtl; charset=utf-8" ><!--PHP中文乱码处理--> <title>php array_product()函数笔记_PHP笔记</title> </head> <body> <?php $arr1=array("2","3","4");//"2"、"3"和"4"会被当中数字2、3和4 $arr2=array("2a","3b","4");//"2a"和"3b"会被当作数字2和3 $arr3=array("a2","3","4"); //"a2"会被当作数字0 echo '"2","3","4":'.array_product($arr1); echo '</br>"2a","3b","4":'.array_product($arr2); echo '</br>"a2","3","4":'.array_product($arr3); ?> </body> </html>
operation result:
The above is the detailed content of PHP function array_product() that calculates and returns the product of an array. For more information, please follow other related articles on the PHP Chinese website!