How to write the syntax for formatting such a json string? (Urgent !) For example, there is a two-dimensional array & nbsp; $ myarrnewsarray (); $ myarrnews & nbsp; explode (| ** |, & nbsp; $ mystr); & nbsp; content comes from $ mystr, including multiple News records $ myarrlinearray (); & nbsp; $ myarrline & nbs help: how to write the syntax to format such a json string? (Urgent !)
For example, there is a two-dimensional array
$ Myarrnews = array ();
$ Myarrnews = explode ("| ** |", $ mystr); // the content comes from $ mystr, including multiple news Records.
$ Myarrline = array ();
$ Myarrline = explode ("| |%%| |", $ myarrnews [$ I]); // $ myarrline is one of the records, including multiple fields
Print_r ($ myarrline); // A set of fields for each news, for example, Array ([0] => 10 [1] => 2166 [2] => innovation...
Now we need a json string in the format of: (set to display 5 entries per page)
{
"Ret": 0,
"Data ":{
"Newslist ":[
{
"Title": "1st News Headlines ",
"Commentcount": 0,
"Source": "source ",
"Nid": 10,
"Digest": "News Introduction ",
"Ptime": "14:11:43"
},
{
"Title": "2nd News Headlines ",
"Commentcount": 0,
"Source": "source ",
"Nid": 9,
"Digest": "News Introduction ",
"Ptime": "13:12:56"
},
{
"Title": "3rd News Headlines ",
"Commentcount": 0,
"Source": "source ",
"Nid": 8,
"Digest": "News Introduction ",
"Ptime": "12:21:11"
},
{
"Title": "4th News Headlines ",
"Commentcount": 0,
"Source": "source ",
"Nid": 7,
"Digest": "News Introduction ",
"Ptime": "11:21:00"
},
{
"Title": "5th News Headlines ",
"Commentcount": 1,
"Source": "source ",
"Nid": 5,
"Digest": "News Introduction ",
"Ptime": "19:20:01"
}
],
"Totalnum": 5
},
"Msg": "OK"
}
//----------------------------
How should I write the php syntax? Please help. please try again!
------ Solution --------------------
$ar = arrat(
' ret' => 0,
'data' => array(
'newslist' => $newslist,