PHP完全自学手册(珍藏版) 中文pdf扫描版下载
//ArrayIterator会把对象或数组封装为一个可以通过foreach来操作的类
$arr = array(
'a' => 'A',
'b' => 'B',
'c' => 'C'
);
$obj = new ArrayIterator($arr);
foreach ($obj as $key => $val){
echo $obj[$key]."<br>";
}
class my_class{
public $a = 'A';
public $b = 'B';
public $c = 'C';
}
$obj = new ArrayIterator(new my_class());
foreach ($obj as $key => $val){
echo $obj[$key]."<br>";
}
$arr = array(
'a' => 'A',
'b' => 'B',
'c' => 'C'
);
$obj = new ArrayIterator($arr);
foreach ($obj as $key => $val){
echo $obj[$key]."<br>";
}
class my_class{
public $a = 'A';
public $b = 'B';
public $c = 'C';
}
$obj = new ArrayIterator(new my_class());
foreach ($obj as $key => $val){
echo $obj[$key]."<br>";
}
转载请注明:谷谷点程序 » php 的 ArrayIterator 说明