Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中将JSON对象转换为纯逗号分隔字符串?_Php_Arrays_Json_String - Fatal编程技术网

如何在php中将JSON对象转换为纯逗号分隔字符串?

如何在php中将JSON对象转换为纯逗号分隔字符串?,php,arrays,json,string,Php,Arrays,Json,String,如何从php中的json对象创建此类字符串,如下所示: var $json = [{name:'abaneel',age:23}, {name: 'john', age: 32}, {name: 'Dev' , age:22} ]; 以下是您需要做的: $simple string ="abaneel,23,john,32,Dev,22"; 希望这将有助于以下是您需要做的事情: $simple string ="abaneel,23,john,32,Dev,22"; $js

如何从php中的json对象创建此类字符串,如下所示:

var $json = [{name:'abaneel',age:23},
    {name: 'john', age: 32},
    {name: 'Dev' , age:22}
];

以下是您需要做的:

$simple string ="abaneel,23,john,32,Dev,22";

希望这将有助于

以下是您需要做的事情:

$simple string ="abaneel,23,john,32,Dev,22";
$json = '[
  {"name": "abaneel", "age" : 23},
  {"name": "john", "age" : 32},
  {"name": "Dev", "age" : 22}
]';
$implode = array();
$multiple = json_decode($json, true);
foreach($multiple as $single)
    $implode[] = implode(', ', $single);

echo implode(', ', $implode);   //this will output abaneel, 23, john, 32, Dev, 22
/*
    You can see that it will be hard to distinguish that where line(one array is ending);
*/
echo implode(' | ', $implode);  //will output abaneel, 23 | john, 32 | Dev, 22
希望这会有所帮助


$json = '[
  {"name": "abaneel", "age" : 23},
  {"name": "john", "age" : 32},
  {"name": "Dev", "age" : 22}
]';
$implode = array();
$multiple = json_decode($json, true);
foreach($multiple as $single)
    $implode[] = implode(', ', $single);

echo implode(', ', $implode);   //this will output abaneel, 23, john, 32, Dev, 22
/*
    You can see that it will be hard to distinguish that where line(one array is ending);
*/
echo implode(' | ', $implode);  //will output abaneel, 23 | john, 32 | Dev, 22


我是堆栈溢出的新手,我不明白你所说的“标记作为答案”是什么意思。。。。但它的工作很好。谢谢你,我的意思是你应该接受这个作为答案,如果你把答案悬停在投票按钮下,会有一个勾号,请勾选。我是堆栈溢出新手,我不明白你所说的标记作为答案是什么意思。。。。但它的工作很好。谢谢你,我的意思是你应该接受这个答案,如果你把答案悬停在投票按钮下,会有一个勾号,请勾选。