fork download
  1. <?php
  2. class Foo {
  3. public $name;
  4. public $type;
  5.  
  6. public function __construct($name, $type) {
  7. $this->name = $name;
  8. $this->type = $type;
  9. }
  10. }
  11.  
  12.  
  13. $array[] = new Foo('first', 0);
  14. $array[] = new Foo('second', 0);
  15. $array[] = new Foo('third', 1);
  16. $array[] = new Foo('fourth', 1);
  17.  
  18. $filter = array_filter($array, function($f) {return ($f->type == 1);});
  19.  
  20. $result = array_diff($array, $filter);
  21.  
  22. print_r($result);
Runtime error #stdin #stdout #stderr 0.02s 24400KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Catchable fatal error:  Object of class Foo could not be converted to string in /home/Cb9m7d/prog.php on line 20