Flow\JSONPath\JSONPath::lastKey PHP Method

lastKey() public method

Evaluate an expression and return the last key
public lastKey ( ) : mixed
return mixed
    public function lastKey()
    {
        $keys = AccessHelper::collectionKeys($this->data);
        if (empty($keys) || end($keys) === false) {
            return null;
        }
        return end($keys);
    }

Usage Example

Beispiel #1
0
 public function testLastKey()
 {
     // Array test for array
     $jsonPath = new JSONPath(array('a' => 'A', 'b' => 'B', 'c' => 'C'));
     $lastKey = $jsonPath->lastKey();
     $this->assertEquals('c', $lastKey);
     // Array test for object
     $jsonPath = new JSONPath((object) array('a' => 'A', 'b' => 'B', 'c' => 'C'));
     $lastKey = $jsonPath->lastKey();
     $this->assertEquals('c', $lastKey);
 }