2

I have an object $stdClassObject that's created by json_decode. It's for train schedules. I need to be able to create a new object which contains just those trains heading east bound. I'm at a loss of how to do this since I'm very new to Objects in PHP. Here is the PHP code I've isolate $trips[$ny_trip]:

// $stdClassObject originally created by json_decode
foreach ($trips as $ny_trip=>$ny_trip_info) {

    if (East_Bound($ny_trip_info->DESTINATION)) {
    // Copy or clone(?) $trips[$ny_trip]) to an object called east_bound
        ...
    }
}
4

1 回答 1

2

我看到两个选项:

  • 实现魔术方法__clone()以能够自定义克隆过程
  • 将此自定义函数添加到您的课程中。喜欢YourClass::customClone($options)

看起来第一个选项套件在这里很好

于 2013-06-17T14:23:15.470 回答