I have this JSON array stored in my database
[{
"prodid": 1,
"optionsids": [],
"extrasids": ["1"]
}, {
"prodid": 2,
"optionsids": [],
"extrasids": ["4"]
}]
I am storing it as an array and when I retrieve it in PHP I am going through this and I am 100 % sure it is wrong
$productsarray=json_encode($row['productids']);
$obj = json_decode($productsarray, TRUE);
so I can then loop to get the prodid value
$products='';
foreach( $obj as $key => $value) {
$value = get_object_vars($value);
$products = $products.$value;
}
But I am getting an Invalid argument supplied for foreach() error which means that $obj is not an array right? idk how to fix this i have tried various things but with no results.
json_encodeit again when you pull it out of the database. Also when usingtrueinjson_decode, the entire$objwill be an associative array, so the subsequentget_object_varscan be unpredictable with an associative array fed into it.