Parkour\Access::has PHP Method

has() public static method

Tells if there is data at the given path.
See also: splitPath()
public static has ( array $data, array | string $path ) : boolean
$data array Data.
$path array | string Path.
return boolean If there is data.
    public static function has(array $data, $path)
    {
        $keys = self::splitPath($path);
        $current = $data;
        foreach ($keys as $key) {
            if (!isset($current[$key])) {
                return false;
            }
            $current = $current[$key];
        }
        return true;
    }

Usage Example

 /**
  *
  */
 public function testHas()
 {
     $data = ['a' => 1, 'b' => ['c' => 2, 'd' => ['e' => 3]]];
     $this->assertTrue(Access::has($data, 'a'));
     $this->assertTrue(Access::has($data, 'b.d.e'));
     $this->assertFalse(Access::has($data, 'a.b.c'));
 }