Inside JSON nested array outpt using PHP -
Inside JSON nested array outpt using PHP -
this json output want
{ "mainevent":"geelong v essendon", "outcomedatetime":"2014-06-27 19:51:00.0000000", "competitors":[ { "name":"geelong", "win":"1.32" }, { "name":"essendon", "win":"3.40" } ] }, { "mainevent":"hawthorn v gold coast", "outcomedatetime":"2014-06-28 13:46:00.0000000", "competitors":[ { "name":"geedlong", "win":"1.32d" }, { "name":"essenddon", "win":"3.40d" } ] } this code
foreach ($sortedbydate $key => $values){ foreach ($json_a $root_element => $childnode) { foreach( $childnode $ckey => $subchild) { $rootobj = array( 'mainevent' => $subchild['mainevent'], 'outcomedatetime' => $subchild['outcomedatetime'], foreach($subchild['competitors']['competitors'] $compkey => $compval) { $teamname = $compval['team']; $win = $compval['win']; $abc = array( "team" => $teamname, "win" => $win, ); } } $rootobj ['competitors'] = $abc; }} $abc=""; print json_encode($rootobj ); } and getting output . comma missing in output. can give me suggestions please?
{ "mainevent":"geelong v essendon", "outcomedatetime":"2014-06-27 19:51:00.0000000", "competitors":[ { "name":"geelong", "win":"1.32" }, { "name":"essendon", "win":"3.40" } ] } { "mainevent":"hawthorn v gold coast", "outcomedatetime":"2014-06-28 13:46:00.0000000", "competitors":[ { "name":"geedlong", "win":"1.32d" }, { "name":"essenddon", "win":"3.40d" } ] } i have tried these code not sure how add together comma in output json
you're printing twice, not have comma;
try this:
$jsons = array(); foreach ($sortedbydate $key => $values){ foreach ($json_a $root_element => $childnode) { foreach( $childnode $ckey => $subchild) { $rootobj = array( 'mainevent' => $subchild['mainevent'], 'outcomedatetime' => $subchild['outcomedatetime'], foreach($subchild['competitors']['competitors'] $compkey => $compval) { $teamname = $compval['team']; $win = $compval['win']; $abc = array( "team" => $teamname, "win" => $win, ); } } $rootobj ['competitors'] = $abc; }} $abc=""; $jsons[] = json_encode($rootobj); } print implode(",",$jsons); doesn't valid json me though
let me know if works.
php arrays multidimensional-array json
Comments
Post a Comment