Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
882 views
in Technique[技术] by (71.8m points)

codeigniter - PHP Array Unique For Duplicate Foreach Result

Got an issue while displaying result array from foreach loop, because contain similiar words while looping so it would make it twice, the code like these below

foreach ($data['terms'] as $term) {
    foreach ($data['links'] as $link) {
        $html = file_get_html($link);
        foreach ($html->find('div[class="item-content item-right"], div[class="col-custom left"],article') as
                 $konten) {
            foreach ($konten->find('h4,h2') as $tags) {
                foreach ($konten->find('a') as $urls) {
                    if (stripos($tags->plaintext, $term) !== false) {
                        $row['judul'] = $tags->plaintext;
                        $row['url'] = $urls->href;

                        $result[] = $row;
                        break;
                    }
                }
            }
        }
    }
}

foreach ($result as $res) {
    echo $res['judul'] . '<br>';
    echo $res['url'] . '<br>';
}

Result will displaying doubled because containing BRI words, but i want to the results not duplicate:

Konsisten Kelola Risiko, BRI Jaga Pencadangan secara Terukur Selama Pandemi
https: //wwwsuaracom/bisnis/2021/01/25/112538/
Rangkul Fans MLBB, BRI Terbitkan BRIZZI Special Edition Mobile Legend
https: //wwwsuaracom/bisnis/2021/01/25/112538/
Konsisten Kelola Risiko, BRI Jaga Pencadangan secara Terukur Selama Pandemi
https: //wwwsuaracom/bisnis/2021/01/25/073116/
Rangkul Fans MLBB, BRI Terbitkan BRIZZI Special Edition Mobile Legend
https: //wwwsuaracom/bisnis/2021/01/23/152844/
Pabrik Pakaian Branded Ini (PBRX) Siap Rilis Surat Utang Hampir Rp5 Triliun
https: //marketbisniscom/read/20210125/192/1347362/
IHSG Terkoreksi 1 Persen Lebih, Saham BBRI Tetap Diburu Asing
https: //marketbisniscom/read/20210125/192/1347362/

question from:https://stackoverflow.com/questions/65880412/php-array-unique-for-duplicate-foreach-result

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...