我如何乘在容易与PHP数组中的每个项目? [英] How can I multiply each item in an array easily with PHP?
本文介绍了我如何乘在容易与PHP数组中的每个项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为阵列 $次
。它体积小号码的列表( 15,14,11,9,3,2
)。这将是用户提交的,并且应该是分钟。随着PHP的时间工作在秒,我想60乘我的数组中的每个元素。
I have an array called $times
. It is a list of small numbers (15,14,11,9,3,2
). These will be user submitted and are supposed to be minutes. As PHP time works on seconds, I would like to multiply each element of my array by 60.
我一直在玩弄 array_walk
和 array_map
,但我不能让这些工作。
I've been playing around with array_walk
and array_map
but I can't get those working.
推荐答案
只是迭代通过使用的foreach
语句和乘法的数组:
Just iterate over the array with the foreach
statement and multiply:
foreach ($times as $value) {
$new_times[] = $value * 60;
}
这篇关于我如何乘在容易与PHP数组中的每个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文