对象可以使用foreach进行遍历,只能遍历属性以及访问范围内的
<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之对象遍历,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。