Foreach Object with one element PHP <p>I have an object called <code>$people</code>. It is filled by my database. This object looks like this:</p> <pre><code>Array ( [0] =&gt; stdClass Object ( [id] =&gt; 21 [fname] =&gt; Billy [lname] =&gt; Boemba [email] =&gt; email@example.com [country] =&gt; The Netherlands ) [1] =&gt; stdClass Object ( [id] =&gt; 22 [fname] =&gt; Jill [lname] =&gt; Jimba [email] =&gt; email@example.com [country] =&gt; Austria ) </code></pre> <p>And my foreach like this:</p> <pre><code>foreach($people as $person){ // echo some stuff about the person } </code></pre> <p>All this works, but when I have one record in my database, so <code>$people</code> has only one element, I got a error when I try to use <code>foreach()</code>:<br/> <code>Notice: Trying to get property of non-object</code></p> <p>So how can I use the <code>foreach()</code> function with one element in my object?</p>