Home  >  Article  >  Backend Development  >  PHP object traversal

PHP object traversal

WBOY
WBOYOriginal
2016-07-29 09:02:001279browse

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>

PHP object traversal

').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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn