3 回答

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超3個(gè)贊
在 Ghost 的回答的幫助下,我們計(jì)算了每個(gè)不同的總和,ifDesc如果它 > 0,我們將添加到一個(gè)新數(shù)組中。
$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貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超4個(gè)贊
我會(huì)做的一種方法是先獲取所有ifDescs。收集所有 em 后,您可以開始處理實(shí)際數(shù)組以刪除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
}
}
但對(duì)于它的價(jià)值。我同意 Barmar 使用查詢的解決方案,以便它可以更好地?cái)U(kuò)展。
- 3 回答
- 0 關(guān)注
- 178 瀏覽
添加回答
舉報(bào)