combine two foreach loops

前端 未结 3 2119
一生所求
一生所求 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:33

    The best answer is probably from Jack, but I thought my solution was interesting. I also tried to improve your code:

    do {
        if ($item = current($items)) {
            $key = key($items);
            $keywords = str_replace(' ', '|');
            list($infoo_str, $title_str) = preg_replace(
                "/\b({$keywords})\b(?![^<]*[>])/i",
                '$0',
                array($infoo[$key], $title[$key])
            );
    
            echo "{$infoo_str}{$title_str}{$item}";
    
            next($items);
        }
    
        if ($linkas = current($linkai)) {
            $characters = array('download/', '&', 'amp;nbsp;', '/i/');
            $replacements = array('files/', '&', ' ', '/IMG/');
            $linkas = str_replace($characters, $replacements, $linkas);
    
            echo "
    "; next($linkai); } } while ($item or $linkas);

提交回复
热议问题