Error: Trying to get property of non-object

0

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

    
asked by Lioni_Lee 26.09.2018 в 11:50
source

2 answers

1

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"]);

  }
    
answered by 26.09.2018 / 16:45
source
0

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);
}
    
answered by 26.09.2018 в 11:56