array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.array-product.php', 1 => 'array_product', ), 'up' => array ( 0 => 'ref.array.php', 1 => '数组 函数', ), 'prev' => array ( 0 => 'function.array-pop.php', 1 => 'array_pop', ), 'next' => array ( 0 => 'function.array-push.php', 1 => 'array_push', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/array/functions/array-product.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
array_product — 计算数组中所有值的乘积
array
这个数组。
以整数或浮点数返回一个数组中所有值的乘积。
版本 | 说明 |
---|---|
8.3.0 |
当 array 值不能转换为 int 或 float 时,现在会发出 E_WARNING 。之前会忽略
array 和 object,而其它的值会转换为 int。此外,现在也会转换定义了数字转换的对象(比如 GMP)而不是忽略它。
|
示例 #1 array_product() 示例
<?php
$a = array(2, 4, 6, 8);
echo "product(a) = " . array_product($a) . "\n";
echo "product(array()) = " . array_product(array()) . "\n";
?>
以上示例会输出:
product(a) = 384 product(array()) = 1