I have a problem accessing a specific data of an array
try
foreach ($data as $value) {
print_r($value->mat_id);
}
and I get Trying to get property of non-object
When you performed the print_r
, the data type gives you as a result that it is a Array , and since it is an array type, it is obviously not an object, therefore, the error
Trying to get property of non-object
To traverse the array using foreach is as follows:
foreach ($data as $value) {
print_r($value["mat_id"]);
}
You're going through it badly. When you do the foreach $ value it assumes the values directly so there is no object.
Try this way
foreach ($data as $clave => $valor) {
print_r($valor);
}