//PHP foreach用于对象的时候【PHP进阶教程】 $arr = array (1, 2, 3, 4, 5 );//this array foreach ( $arr as $a => $value ) { // print_r ( $a );//this key } foreach ( $arr as $a ) { //print_r ( $a ); //this is value } class MyPc{ public $_helper; public $_other; function __construct(){ $this->_helper=array('name'=>'wolf','age'=>'man'); $this->_other=array('dept'=>'Goverment','Slov'=>'1000'); } } $pc=new MyPc();//object foreach($pc as $a){ print_r($a);//this array } foreach($pc as $a=>$value){ print_r($a);//_helper ;_other }