如何在php中将JSON对象转换为纯逗号分隔字符串?
如何从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
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
我是堆栈溢出的新手,我不明白你所说的“标记作为答案”是什么意思。。。。但它的工作很好。谢谢你,我的意思是你应该接受这个作为答案,如果你把答案悬停在投票按钮下,会有一个勾号,请勾选。我是堆栈溢出新手,我不明白你所说的标记作为答案是什么意思。。。。但它的工作很好。谢谢你,我的意思是你应该接受这个答案,如果你把答案悬停在投票按钮下,会有一个勾号,请勾选。