3 回答
TA贡献1830条经验 获得超3个赞
在 Ghost 的回答的帮助下,我们计算了每个不同的总和,ifDesc如果它 > 0,我们将添加到一个新数组中。
$ifDescs = array_unique(array_column($rows, 'ifDesc'));
$recalculatedRows = [];
foreach ($ifDescs as $currentIfDesc) {
$current_batch = [];
foreach ($rows as $k => $row) {
if ($row['ifDesc'] === $currentIfDesc) {
$current_batch[$k] = $row;
}
}
if (array_sum(array_column($current_batch, 'Octets')) > 0) { //sum of Octets > 0 ?
foreach ($current_batch as $r) { //if yes, loop through $current_batch
$recalculatedRows[] = $r; //adding series to new array
}
}
}
echo json_encode($recalculatedRows);
TA贡献1831条经验 获得超4个赞
我会做的一种方法是先获取所有ifDescs。收集所有 em 后,您可以开始处理实际数组以删除ifDesc总和为零的s批次。
$ifDescs = array_unique(array_column($rows, 'ifDesc')); // get all ifDescs
foreach ($ifDescs as $currentIfDesc) { // loop each ifDesc batches
$current_batch = []; // set initial batch of ifDesc type for temporary container
foreach ($rows as $k => $row) { // group them first
if ($row['ifDesc'] === $currentIfDesc) {
$current_batch[$k] = $row;
}
}
$non_zero_octets = array_sum(array_column($current_batch, 'Octets')) > 0; // get all octets of the current batch iteration, and check if its greater than one when summed
if (!$non_zero_octets) { // if not greater than zero
$rows = array_diff_key($rows, array_keys($current_batch)); // remove em using all the keys
}
}
但对于它的价值。我同意 Barmar 使用查询的解决方案,以便它可以更好地扩展。
- 3 回答
- 0 关注
- 151 浏览
添加回答
举报