Home > Article > Backend Development > PHP object traversal
Objects can be traversed using foreach, which can only traverse attributes and access
<code><span><span><?php </span><span><span>class</span><span>bee</span>{</span><span>public</span><span>$a</span> = <span>1</span>; <span>protected</span><span>$b</span> = <span>2</span>; <span>private</span><span>$c</span> = <span>3</span>; } <span>$obj</span> = <span>new</span> bee(); <span>foreach</span>(<span>$obj</span><span>as</span><span>$key</span> => <span>$val</span>){ <span>echo</span><span>$key</span>.<span>'-'</span>.<span>$val</span>; }</span></span></code>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });
The above has introduced object traversal in PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.