Array foreach loop PHP

后端 未结 2 1254
后悔当初
后悔当初 2021-01-20 16:34

Hello everyone here is my case:

I\'m crawling through the old page with more than 10 000 comments which I\'m trying to import to WordPress.

I\'m using simpl

2条回答
  •  面向向阳花
    2021-01-20 17:29

    You are getting the array two times because you are adding whole array value $commItem to $commArr during both odd and even numbers using if condition. That's why you are getting array double time.

    Replace your code

    foreach($rawComm as $commItem) {
        if($z % 2 == 0) {
            $commArr['text']    = $commItem;
        }else{
            $commArr['sign']    = $commItem;
            //echo $commItem;
        }
        echo 'Numer wpisu: '.$z.'
    '; $z++; }

    to this one

    foreach($rawComm as $commItem) {    
        $commArr[] = array('text'=>$commItem[0], 'sign'=>$commItem[1]);
    }
    

    I think this might work for you :).

提交回复
热议问题