Reputation: 13368
I Need JSON encode format like below structure.Product,productinfo values are dynamically get from MySQL database.
{
"Product": [{
"mainid": "1",
"productinfo": [{
"subid": "1222",
"rate": "4"
}, {
"subid": "1222",
"rate": "74"
}, {
"subid": "1222",
"rate": "49"
}]
}, {
"mainid": "2",
"productinfo": [{
"subid": "224",
"rate": "86"
}, {
"subid": "122255",
"rate": "55"
}, {
"subid": "12252",
"rate": "54"
}]
}
]
}
Upvotes: 1
Views: 7724
Reputation: 11
$make=array();
$vtype=array();
$index = array(
'make'=>$make,
'vtype'=>$vtype,
);
Upvotes: 0
Reputation: 512
fist of all creat a multidimensioal array to respresent that then encode it to json format.like this:
$array = array(
'product'=>array(
'mainid'=>1,
"productinfo"=>array(
0=>array('subid'=>1222 ,'rate'=>4),
1=>array("subid"=>"1222",
"rate"=>"74")
//and so on
)
),
);
then you encode it into josn using:
json_encode($array);
Upvotes: 2