在PHP中是否有任何方法(轻松)以递归方式替换具有内容的对象属性?
ie:我想通过这个对象递归地删除“data”属性。所以它不是一个“中间人”
这样我就不必致电$foo->data->bar->data->id
而我可以致电$foo->bar->id
object(stdClass)[251]
public 'data' =>
object(stdClass)[224]
public 'id' => string '1730e209-0cbf-4598-8e5a-c5ca8469e8b9' (length=36)
public 'level_id' => string '12cada4e-0874-490e-adce-b58700244446' (length=36)
public 'level' =>
object(stdClass)[250]
public 'data' =>
object(stdClass)[252]
...
object(stdClass)[251]
public 'id' => string '1730e209-0cbf-4598-8e5a-c5ca8469e8b9' (length=36)
public 'level_id' => string '12cada4e-0874-490e-adce-b58700244446' (length=36)
public 'level' =>
object(stdClass)[250]
...
答案 0 :(得分:0)
foreach ($foo->data as $d){
$id = $d->bar->data->id;
... // do what you should here with $d children
}