combine two foreach loops

前端 未结 3 1998
一生所求
一生所求 2021-02-06 16:16

I have two foreach loops: 1st one:

        foreach ($items as $key => $item) 
        {   
        $keywords = explode(\' \', $qsvarus);
        $title[$key]          


        
3条回答
  •  情歌与酒
    2021-02-06 16:22

    You can use the MultipleIterator for this:

    $m = new MultipleIterator();
    $m->attachIterator(new ArrayIterator($items), 'item');
    $m->attachIterator(new ArrayIterator($linkai), 'linkas');
    
    foreach ($m as $unit) {
        // $unit['item'] contains an entry from $items
        // $unit['linkas'] contains an entry from $linkai
    
        // your logic here
    }
    

提交回复
热议问题