How to transform json data to a comma separated php string?

后端 未结 3 469
情歌与酒
情歌与酒 2021-01-20 14:03

Let\'s say i have this json data. How to transform the \"tags\" to a string like

$tags = \"Rihanna, We, Found, Love, (Explicit), Def, Jam, Records, Pop\";

相关标签:
3条回答
  • 2021-01-20 14:14

    Try:

    foreach($videosList as $i=>$video){
        $videosDatas['videos'][$i]['title'] = $video->title;
        $tags = implode(', ',$video->tags);
        $videosDatas['videos'][$i]['tags'] = $tags;
    }
    

    In place of your code:

    for($i=0; $i<count($videosList); $i++) {
    
    $videosDatas['videos'][$i]['title'] = $videosList[$i]['title'];
    
    }
    
    0 讨论(0)
  • 2021-01-20 14:29
    $comma_sep_string = implode(', ' , $videosDatas['videos'][$i]['tags']);
    
    0 讨论(0)
  • 2021-01-20 14:32

    It looks like you need implode(). The function would be something like...

    $tags = implode(', ', $videosDatas['videos'][$i]['tags']);
    
    0 讨论(0)
提交回复
热议问题