I have a result set which looks something like this:
For each entry, there can be more than one category and I'm trying to decode these JSON strings and save it in a single array. That means, all these categories will be decoded and saved in an array. This data is fetched from database.
This is the code I tried:
//$resultset contains the entire resultset
$resultset_JSON='[["first","second","third","fourth"],["fifth","sixth","seventh","eight","ninth"],["life","death","business" ,"editing","light"]]';
$data= array();
while($row=mysqli_fetch_array($resultset))
{
$data = json_decode($row['category']);
//$data[] = json_decode($row['category']);
}
print_r($data);
But I'm not getting the desired result. I'm only able to fetch the last row.
Can anyone help me figure this out?
This is the output I'm trying to get:
Array
(
[0] => first
[1] => second
[2] => third
[3] => fourth
[4] => fifth
[5] => sixth
[6] => seventh
[7] => eighth
[8] => ninth
[9] => life
[10] => death
[11] => business
[12] => editing
[13] => light
)

[]at$data[]=json_decode($row['category']);$data[] = $row['category'];and outside while loopjson_decode($data)