实例
计算并返回数组的乘积:
<?php $a=array(5,5); echo(array_product($a)); ?>
定义和用法
array_product() 函数计算并返回数组的乘积。
语法
array_product(array)
| 参数 | 描述 |
| array | 必需。规定数组。 |
技术细节
| 返回值: | 返回一个整数或者浮点数的乘积。 |
| PHP 版本: | 5.1.0+ |
| 更新日志: | 自 PHP 5.3.6 起,空数组的乘积为 1。在 PHP 5.3.6 之前,空数组的乘积为 0。 |
更多实例
实例 1
计算并返回数组的乘积:
<?php $a=array(5,5,2,10); echo(array_product($a)); ?>
实例1( 纯数字不含字符串的数组):
<?php $arr=array(2,3,4); echo array_product($arr); ?>
输出结果:24
实例(含字符串的数组):
立即学习“PHP免费学习笔记(深入)”;
<!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>运行结果:![1510108574399770.png }V~}X]S3TI}DA`6B~9CHC0T.png](https://img.php.cn//upload/image/819/134/556/1510108574399770.png)
以上就是php计算并返回数组的乘积的函数array_product()的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号