Collections\Collection::findLastIndex PHP Method

findLastIndex() public method

public findLastIndex ( callable $condition )
$condition callable
    public function findLastIndex(callable $condition)
    {
        $index = -1;
        for ($i = count($this->items) - 1; $i >= 0; $i--) {
            if ($condition($this->items[$i])) {
                $index = $i;
                break;
            }
        }
        return $index;
    }

Usage Example

 public function test_find_last_index_when_not_found()
 {
     $col = new Collection('int', [1, 2, 3]);
     $index = $col->findLastIndex(function ($x) {
         return $x === 4;
     });
     $this->assertEquals(-1, $index);
 }