I've got a list of objects:
0 =>
object(stdClass)[550]
public 'node_title' => string 'Test' (length=4)
public 'nid' => string '1473' (length=4)
public 'node_language' => string 'nl' (length=2)
1 =>
object(stdClass)[552]
public 'node_title' => string 'Test2' (length=5)
public 'nid' => string '1321' (length=4)
public 'node_language' => string 'nl' (length=2)
2 =>
object(stdClass)[553]
public 'node_title' => string 'Test3' (length=5)
public 'nid' => string '602' (length=3)
public 'node_language' => string 'nl' (length=2)
And I loop over them using a foreach loop:
foreach($view->result as $key => $value) {
}
So, if every time the foreach loops, 1 object is fetched, right?
But how can I access one item of the object? I've tried with 0->nid, $key->nid,... but nothing worked... How can I do so?
foreachdocumentation. As the variable names already suggest,$keyis the index of the array element, while$valueis, surprise, the value. If you don't know which of these to use, you can simply inspect them withprint_r($key)andprint_r($value).