1

I think the code is obvious:

foreach ($programs as $program) {
    if ($program->name == 'foo') {
        unset($program);
    }
}

But it's not working!
Isn't it possible to unset current property? Where's the problem? Is there any alternatives?

Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
Farid Rn
  • 3,167
  • 5
  • 39
  • 66

1 Answers1

4
foreach ($programs as $property => $program) {
//                    ^-----------^ added
    if ($program->name == 'foo') {
        unset($programs->$property);
//                     ^---------^ added
    }
}
salathe
  • 51,324
  • 12
  • 104
  • 132