Flow\JSONPath\JSONPath::firstKey PHP Méthode

firstKey() public méthode

Evaluate an expression and return the first key
public firstKey ( ) : mixed
Résultat mixed
    public function firstKey()
    {
        $keys = AccessHelper::collectionKeys($this->data);
        if (empty($keys)) {
            return null;
        }
        return $keys[0];
    }

Usage Example

Exemple #1
0
 public function testFirstKey()
 {
     // Array test for array
     $jsonPath = new JSONPath(array('a' => 'A', 'b', 'B'));
     $firstKey = $jsonPath->firstKey();
     $this->assertEquals('a', $firstKey);
     // Array test for object
     $jsonPath = new JSONPath((object) array('a' => 'A', 'b', 'B'));
     $firstKey = $jsonPath->firstKey();
     $this->assertEquals('a', $firstKey);
 }