如何将json数据转换为逗号分隔的php字符串?

m3t*_*sys 2 php json

假设我有这个json数据.如何将"标签"转换为类似的字符串

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

{ "apiVersion" : "2.1",
      "data" : { "items" : [ { "accessControl" : { "autoPlay" : "allowed",
                    "comment" : "allowed",
                    "commentVote" : "allowed",
                    "embed" : "allowed",
                    "list" : "allowed",
                    "rate" : "allowed",
                    "syndicate" : "allowed",
                    "videoRespond" : "allowed"
                  },
                "aspectRatio" : "widescreen",
                "category" : "Music",
                "tags" : [ "Rihanna",
                    "We",
                    "Found",
                    "Love",
                    "(Explicit)",
                    "Def",
                    "Jam",
                    "Records",
                    "Pop"
                  ],
                "title" : "Rihanna - We Found Love ft. Calvin Harris"
              } ],
          "itemsPerPage" : 1,
          "startIndex" : 1,
          "totalItems" : 859012,
          "updated" : "2012-04-04T20:32:26.170Z"
        }
    }
Run Code Online (Sandbox Code Playgroud)

以标题为例,脚本如下所示:

$content = $this->getDataFromUrl($feedURL);
$content = json_decode($content,true);

$videosList = $content['data']['items'];

for($i=0; $i<count($videosList); $i++) {

$videosDatas['videos'][$i]['title'] = $videosList[$i]['title'];

}
Run Code Online (Sandbox Code Playgroud)

Chr*_*lin 5

看起来你需要implode().这个功能就像......

$tags = implode(', ', $videosDatas['videos'][$i]['tags']);
Run Code Online (Sandbox Code Playgroud)