i have a problem here. so, i try to make nested array for my json using php and this is what im getting
[
{
"ID":"3301",
"NAME":"cust 01",
"ID2":"33"
},
{
"ID":"3301",
"NAME":"cust 01",
"ID2":"33"
}
]
but i want to make it like this
[
{
"ID":"3301",
"NAME":"cust 01",
"attribut":
[
{
"ID2":"33"
}
]
},
{
"ID":"3301",
"NAME":"cust 01",
"attribut":
[
{
"ID2":"33"
}
]
}
]
this is the code
//Query
$sql = 'select * from mytable';
$query = mysqli_query($con,$sql);
while($data=mysqli_fetch_array($query,MYSQLI_ASSOC))
$output[]=$data;
// json
echo json_encode($output);
can someone help me?
attributalways just an array with one element? If so, change'ID2' => $valueto'attribut' => [['ID2' => $value]]