关于我的密码我有个问题。我有这样的数据:
Array
(
[12x2060] => Array
(
[hashrate] => 12
[sharesPerSecond] => 0.0188125
)
[6x3080ti] => Array
(
[hashrate] => 44
[sharesPerSecond] => 0.0185625
)
[8x1660s] => Array
(
[hashrate] => 11
[sharesPerSecond] => 0.00975
)
)
Array
(
[12x2060] => Array
(
[hashrate] => 5
[sharesPerSecond] => 0.0188125
)
[6x3080ti] => Array
(
[hashrate] => 8
[sharesPerSecond] => 0.0185625
)
[8x1660s] => Array
(
[hashrate] => 3
[sharesPerSecond] => 0.00975
)
)更多的是类似历史统计的数据。我想要计算哈希率变成这样:
总哈希率= 67
totalhashrate2 = 16
而像12x2060,6x3080ti这样的名称则随机依赖于用户数据。
有人要告诉我密码怎么做吗?
发布于 2022-03-05 16:59:48
您可以使用,然后使用返回数据的。
$total = array_sum(array_column($array, 'hashrate'));使用您的示例数据:
$array = [];
$array['12x2060']['hashrate'] = 12;
$array['12x2060']['sharesPerSecond'] = 0.0188125;
$array['6x3080ti']['hashrate'] = 44;
$array['6x3080ti']['sharesPerSecond'] => 0.0185625
$array['8x1660s']['hashrate'] => 11;
$array['8x1660s']['sharesPerSecond'] => 0.00975;然后你可以:
$totalHashRate = array_sum(array_column($array, 'hashrate'));
print $totalHashRate;
// Prints 67发布于 2022-03-05 17:05:39
您可以尝试如下所示:
$arr1 = [
'111' => [
'hashrate' => 23
],
'112' => [
'hashrate' => 134
]
];
$arr2 = [
'222' => [
'hashrate' => 1
],
'223' => [
'hashrate' => 10
]
];
// From this
$hashrate1 = 0;
foreach ($arr1 as $key => $value) {
$hashrate1 += $value['hashrate'];
}
$hashrate2 = 0;
foreach ($arr2 as $key => $value) {
$hashrate2 += $value['hashrate'];
}
var_dump($hashrate1, $hashrate2);结果会是这样:
int(157) int(11)https://stackoverflow.com/questions/71364084
复制相似问题