fork download
  1. <?php
  2.  
  3. ini_set('display_errors', true);
  4.  
  5. class Test
  6. {
  7. public $name;
  8. }
  9.  
  10. $test1 = new Test;
  11. $test1->name = 'hello';
  12.  
  13. $test2 = new Test;
  14. $test2->name = 'world';
  15.  
  16. $arr = array($test1, $test2);
  17. unset($test1);
  18.  
  19. foreach ($arr as $test) {
  20. if ($test->name == 'hello') unset($test);
  21. /* Так только работает:
  22.   if ($test->name == 'hello') {
  23.   $index = array_search($test, $arr);
  24.   unset($arr[$index]);
  25.   }*/
  26. }
  27.  
  28. var_dump($arr);
Success #stdin #stdout 0.03s 52432KB
stdin
Standard input is empty
stdout
array(2) {
  [0]=>
  object(Test)#1 (1) {
    ["name"]=>
    string(5) "hello"
  }
  [1]=>
  object(Test)#2 (1) {
    ["name"]=>
    string(5) "world"
  }
}