【问题标题】:laravel 8 multiple array value by the indexlaravel 8 多个数组值按索引
【发布时间】:2021-07-25 13:04:48
【问题描述】:

我有 2 个数组,我想要的只是索引的多个数组值,例如 0=> 1 * 0=>1000001=> 2 * 1=>90000 等。这可能吗?

数组 1:

array:2 [▼
  0 => 1
  1 => 2
 next value ...
]

数组 2:

array:2 [▼
  0 => 100000
  1 => 90000
 next value ...
]

如果有人帮忙,非常感谢。

【问题讨论】:

  • 看不懂例子,1*0不是100000
  • 它的索引,索引为0,值为1和100000
  • ( 0=> ) 其索引等

标签: arrays laravel laravel-8


【解决方案1】:
    $arr1 = [0 => 1, 1 => 2];
    $arr2 = [0 => 100000, 1 => 90000];
    foreach ($arr1 as $k => $val) {
        $total[$k]=$val * $arr2[$k];
    }

$total 将返回相乘值列表,我假设 $arr2$arr1 具有相同的键数。

【讨论】:

  • @Reynaldo ,如果您认为这有帮助,请投票并接受我的回答,谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-07-10
  • 1970-01-01
  • 2019-03-11
  • 1970-01-01
  • 1970-01-01
  • 2016-06-02
  • 2013-01-29
相关资源
最近更新 更多