gpt4 book ai didi

function - 使用 implode 不显示给定列的全部值

转载 作者:行者123 更新时间:2023-12-02 03:44:07 28 4
gpt4 key购买 nike

  <?php

$data='{
"id": "621805046",
"likes": {
"data": [
{
"category": "Movie",
"name": "Pyaar Ka PUNCHnama",
"created_time": "2013-08-13T10:11:23+0000",
"id": "151480271575584"
},
{
"category": "Company",
"name": "Ardent Architects",
"created_time": "2013-08-05T09:06:43+0000",
"id": "208530229271384"
},
{
"category": "School",
"name": "APS Confessions",
"created_time": "2013-08-04T04:02:28+0000",
"id": "349865055122777"
},
{
"category": "Education",
"category_list": [
{
"id": "151676848220295",
"name": "Education"
}
],
"name": "Adhyan",
"created_time": "2013-07-31T17:56:58+0000",
"id": "165231053638461"
},
{
"category": "Community",
"name": "Wallpapers",
"created_time": "2013-07-23T18:35:59+0000",
"id": "164958583664617"
},
{
"category": "Software",
"name": "Hill Climb Racing",
"created_time": "2013-07-17T05:28:31+0000",
"id": "401178656621800"
},
{
"category": "Games/toys",
"name": "Hill Climb Racing",
"created_time": "2013-07-17T05:28:18+0000",
"id": "431491673581713"
},
{
"category": "Public figure",
"name": "Aanya Kaul",
"created_time": "2013-07-16T05:12:50+0000",
"id": "176616425843752"
}
]
}
}';



$values = json_decode($data,true);
foreach ($values as $value=>$vv){


foreach($vv as $v1=>$v2){
foreach($v2 as $v4=>$v3){
$g=count($v2);
$fields=array();
foreach($v3 as $v7=>$v8){
if($g++!=0)
$v7 = $v7;
$v8 = mysql_real_escape_string($v8);
$fields[] .= "'$v8'";
}
echo $fields = implode(" , ", $fields);
?>

当我回显 $fields 时,它只显示 -:

** '电影'、'Pyaar Ka PUNCHnama'、'2013-08-13T10:11:23+0000'、'151480271575584'、'公司'、'Ardent Architects'、'2013-08- 05T09:06:43+0000' , '208530229271384', '学校' , 'APS 自白' , '2013-08-04T04:02:28+0000' , '349865055122777', '教育' , '' , 'Adhyan' , '2013-07-31T17:56:58+0000' , '165231053638461**

我不明白为什么会这样。我得到第一个三个阵列,但之后它就停止了。

最佳答案

$res = json_decode($str,true);

/*echo "<pre>";
print_r($res);
echo "</pre>";*/
$res = $res['likes']['data'];
for ($i=0; $i < count($res); $i++){
echo $res[$i]['category'] . " | " . $res[$i]['name'] . " | " . $res[$i]['created_time'] . " | " . $res[$i]['id'] ;
if (array_key_exists("category_list",$res[$i])) {
$cl = $res[$i]['category_list'];
echo " | ";
foreach($cl as $icl) {
echo $icl['name'].",";
}
}
echo "<hr />";

关于function - 使用 implode 不显示给定列的全部值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18215061/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com