php - 将平面数组中的每个整数乘以 60

标签 php arrays time multiplication datetime-conversion

我有一个名为$times 的数组。它是一个小数字列表 (15,14,11,9,3,2)。这些将由用户提交,应该是分钟。由于 PHP 时间以秒为单位,我想将数组的每个元素乘以 60。

我一直在尝试使用 array_walkarray_map 但我无法让它们正常工作。

最佳答案

您可以使用 array_map :

array_map() returns an array containing all the elements of arr1 after applying the callback function to each one. The number of parameters that the callback function accepts should match the number of arrays passed to the array_map()

用于回调的 lambda 函数示例:

array_map(function($el) { return $el * 60; }, $input);

同样适用于 PHP < 5.3

array_map(create_function('$el', 'return $el * 60;'), $input);

或用bcmul回调

array_map('bcmul', $input, array_fill(0, count($input), 60));

但是为此使用 foreach 也没有错。

关于php - 将平面数组中的每个整数乘以 60,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2660152/

相关文章:

Php PDO 没有更新,不知道为什么

c - 将用户的int变量存储到C中的数组中

java - 仅比较两个日期的时间部分,忽略日期部分

php - 添加时间(HH :MM) to <li> tags through jquery

java - Android更改表示时间和日期的字符串的格式

php - 合并两个数组并按日期排序这个新数组

php - 有没有办法确保人们无法访问页面,除非他们已经用 php 完成了 paypal 表单?

php - Highcharts 从 php mysql 钻取 json

javascript - 使用带有 jquery 的内部数组第一项从数组中删除数组

c - 删除重复值并在其位置添加 0