PHP code example of pallares / query-syntax

1. Go to this page and download the library: Download pallares/query-syntax library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pallares / query-syntax example snippets


$query = 'director:"Steven Spielberg" AND (category:"sci-fi" OR category:terror)';

$lexer = new Pallares\QuerySyntax\Lexer($query);

$ast = (new Pallares\QuerySyntax\Parser)->parse($lexer);

$ast === [
    'operator' => 'and',
    'children' => [
        ['operator' => 'comparison', 'key' => 'director', 'value' => 'Steven Spielberg'],
        [
            'operator' => 'or',
            'children' => [
                ['operator' => 'comparison', 'key' => 'category', 'value' => 'sci-fi'],
                ['operator' => 'comparison', 'key' => 'category', 'value' => 'terror'],
            ],
        ]
    ],
];