第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如果所有值都等于 0,則刪除數(shù)組中的系列

如果所有值都等于 0,則刪除數(shù)組中的系列

PHP
明月笑刀無情 2021-10-15 15:52:48
我想查看一個(gè)名為$rows. 對(duì)于 中的每個(gè)不同系列ifDesc,如果全部 Octets都0刪除它們,但是如果單個(gè)條目 > 0,則保留整個(gè)系列,包括該不同的 0ifDesc我嘗試使用 foreach 使用 PHP 或 JavaScript(因?yàn)樗鳛?ajax 響應(yīng)傳遞)循環(huán)遍歷這個(gè),但是我在使用不同的 ifDesc這是為了可讀性而編碼的數(shù)組 json。當(dāng)這些數(shù)據(jù)被傳遞到圖表時(shí),我希望消除圖表底部所有值都為 0 的一系列線。在上面的數(shù)組中,我希望刪除imq0 - In, lo - In&lo - Out作為 all Octets= 0的總和。
查看完整描述

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);


查看完整回答
反對(duì) 回復(fù) 2021-10-15
?
慕容708150

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ò)展。


查看完整回答
反對(duì) 回復(fù) 2021-10-15
  • 3 回答
  • 0 關(guān)注
  • 178 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)