combine two foreach loops

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

    The obvious solution:

    $output1 = array();
    $output2 = array();
    
    foreach ($items as $key => $item) 
    {   
        $keywords = explode(' ', $qsvarus);
        $title[$key] = preg_replace('/\b('.implode('|', $keywords).')\b(?![^<]*[>])/i', '$0', $title[$key]);
        $infoo[$key] = preg_replace('/\b('.implode('|', $keywords).')\b(?![^<]*[>])/i', '$0', $infoo[$key]);
        $output1[] = ''.$title[$key].$infoo[$key].$item.'';
    }
    
    foreach ($linkai as $key => $linkas) {
        $i++;
        $a1 = $linkas[1];
        $a2 = str_replace("download/", "files/", $a1);
        $a3 = str_replace("&","&", $a2);
        $a4 = str_replace("amp;nbsp;","nbsp;", $a3);
        $output2[] = "
    "; } $output = array_map( null, $output1, $output2 ); foreach ( $output as $lines ) { $lines = array_filter( $lines ); foreach ( $lines as $line ) { echo $line; } }

提交回复
热议问题