var $json = [{name:'abaneel',age:23},
{name: 'john', age: 32},
{name: 'Dev' , age:22}
];
How to create this type of string from this json object in php as like this string:
$simple string ="abaneel,23,john,32,Dev,22";
here what you need to do:
$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
hope this will help
<?php
$json ='[
{"name": "abaneel", "age" : 23},
{"name": "john", "age" : 32},
{"name": "Dev", "age" : 22}
]';
$data=json_decode($json,true);
$your_string="";
foreach($data as $key=>$v){
$your_string.=$data[$key]['name'].",".$data[$key]['age'].",";
}
$your_string= trim($your_string, ",");
echo $your_string;
?>