function _lastIndexOf($array, $item) { return Underscore::lastIndexOf($array, $item); }
/** * @tags arrays */ public function testLastIndexOf() { $values = [1, 2, 3, 2, 1]; // it should return the last position of given element $this->typeTolerant($values, null, function ($in, $out) { $this->variable(_::lastIndexOf($in, 2))->isEqualTo(3); }, [0, -1]); // it should return -1 if the element is not in the list $this->typeTolerant($values, null, function ($in, $out) { $this->variable(_::lastIndexOf($in, 5))->isEqualTo(-1); }, [0, -1]); // it should return the key instead of offset when used with an hashmap $values = ['a' => 1, 'b' => 2, 'c' => 3]; $this->typeTolerant($values, null, function ($in, $out) { $this->variable(_::lastIndexOf($in, 2))->isEqualTo('b'); }, [0, -1]); }