Parkour\Traverse::findKey PHP Method

findKey() public static method

Finds a value in the given data and returns its key.
public static findKey ( array $data, callable $cb, mixed $default = null ) : integer | string
$data array Data.
$cb callable Function to find value.
$default mixed Default value.
return integer | string Key.
    public static function findKey(array $data, callable $cb, $default = null)
    {
        foreach ($data as $key => $value) {
            if (call_user_func($cb, $value, $key)) {
                return $key;
            }
        }
        return $default;
    }

Usage Example

 /**
  *
  */
 public function testFindKeyDefault()
 {
     $this->assertEquals('default', Traverse::findKey([], new Identity(), 'default'));
 }