【发布时间】:2011-11-02 11:36:30
【问题描述】:
我在 PHP 中有一个对象,我正在使用一个
foreach ($items as $item)
遍历项目。但是,$item 包含另一个名为 $item 的对象,其中包含我需要访问其值的 $type 变量。如何访问 $type 的值?我想做的是:
foreach($items as item){
if($item->item->type == 'this'){
//do this
} elseif ($item->item->type == 'that'){
//do that
}
}
但是 $item->item->type 并没有获得那个值。如何访问它并将其用于我的功能?
【问题讨论】:
-
我不知道它是否与您的示例以外的任何内容相关,但在您的示例代码中,foreach 语句中的“item”缺少应该在其前面的 $。
标签: php oop variables object foreach