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
  • 44,769
  • 7
  • 56
  • 100
Farid Rn
  • 3,089
  • 5
  • 35
  • 64

1 Answers1

4
foreach ($programs as $property => $program) {
//                    ^-----------^ added
    if ($program->name == 'foo') {
        unset($programs->$property);
//                     ^---------^ added
    }
}
salathe
  • 50,055
  • 11
  • 103
  • 130