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. $array[] = new Foo('first', 0);
  13.  
  14. $second = new Foo('second', 0);
  15. $array[] = $second;
  16. $array[] = new Foo('third', 1);
  17. $array[] = new Foo('fourth', 1);
  18.  
  19. $key = array_search($second, $array, true);
  20.  
  21. print_r($key);
  22.  
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
1