php - Cannot use object of type MongoId as array -
im having problem printing out values inside 2d array using echo, works prefectly using print_r:
print_r($array);
the result of :
array ( [0] => mongoid object ( [$id] => 57a789b7ce2350b40e000029 ) [1] => mongoid object ( [$id] => 57a72d35ce2350681200002b ) [2] => 3 )
however when try access values using:
echo $similar[0][1]; //or echo $similar[0][0];
i error : 'cannot use object of type mongoid array'
i have tried different types of loops here incase error triggered accessing values element number, got same error , im unsure why. appreciated :)
since $similar[0]
mongoid object, , want access $id
must use $similar[0]->{'$id'})
in example elements 0 , 1 mongoid objects, while element 2 integer of 3.
so how print them all
echo $similar[0]->{'$id'}) # gives 57a789b7ce2350b40e000029 echo $similar[1]->{'$id'}) # gives 57a72d35ce2350681200002b echo $similar[2] # gives 3
Comments
Post a Comment