如何对这个数组求和?

2022-01-09 00:00:00 arrays sum php

我想对所有 [Suggested] 字段求和.请问我该怎么做?我使用 PHP.

I'd like to make a sum of all [Suggested] field. How can I make it please? I use Php.

Array
(
    [0] => Array
        (
            [Id] => 4
            [Suggested] => 1322
            [proximite_r] => 30924.8470655462
        )

    [1] => Array
        (
            [Id] => 7
            [Suggested] => 773
            [proximite_r] => 32229.1036975145
        )
)

谢谢!

推荐答案

你可以试试这个:

$Sum = 0;
foreach ($row as $item) {
   $Sum += $item['Suggested']; // or else index
}
echo $Sum;

相关文章