将数组数组转换为jSON并使用php打印出来

时间:2015-04-23 09:11:57

标签: php arrays json

我从选择查询中得到了这个:

Array ( [0] => Array ( [id] => 1 [id_user] => 1 [id_category] => 1 [name] => Bambas futbol sala [description] => Bambas de futbol sala marca nike, color rojo y negro. Pie 43. [localization] => Barcelona [min_bid] => 25 [expiration] => 300 [terms] => - [highlights] => 0 ) [1] => Array ( [id] => 2 [id_user] => 1 [id_category] => 6 [name] => Bateria electronica Roland td4 [description] => Vendo bateria electronida roland td4 kv versi�n 2009 por falta de tiempo. [localization] => Madrid [min_bid] => 600 [expiration] => 200 [terms] => - [highlights] => 0 ) )

我想把它解析成像这样的json(带有我在数组中得到的所有字段)

"infos":[ [ { "id_user":"1", "id_category":"1", "name":"Bambas futbol sala", "description":"..." }, { "id_user":"2", "id_category":"3", "name":"Bambas futbol sala", "description":"..." } ] ],

我怎么能这样做并用PHP打印?感谢

1 个答案:

答案 0 :(得分:1)

使用json_encodejson_decode