PHP code example of rentalhost / vanilla-array-query

1. Go to this page and download the library: Download rentalhost/vanilla-array-query 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/ */

    

rentalhost / vanilla-array-query example snippets




use Rentalhost\Vanilla\ArrayQuery\ArrayQuery;

ArrayQuery::query(
    [ 'name' => 'John Doe', 'age' => 30 ],
    [ 'age' ]
) === [ 'age' => 30 ];

$page = [ 
    'route'       => '/home', 
    'title'       => 'Home', 
    'description' => 'Initial page',
];

ArrayQuery::query($page, [ 'route', 'title' ]) === [
    'route' => '/home', 
    'title' => 'Home', 
];

$page = [ 
    'header' => [ 
        'title'       => 'Home', 
        'description' => 'Initial page',
    ],
];

ArrayQuery::query($page, [ 'header' => [ 'title' ] ]) === [ 
    'header' => [ 
        'title' => 'Home', 
    ],
];

$pages = [
    [
        'route' => '/home',
        'title' => 'Home',
    ],
    [
        'route' => '/admin',
        'title' => 'Administrative',
    ],
];

ArrayQuery::query($pages, [ [ 'route' ] ]) === [
    [
        'route' => '/home',
    ],
    [
        'route' => '/admin',
    ],
];

$page = [ 
    'header' => [ 
        'title' => 'Home', 
        'description' => 'Initial page' 
    ] 
];

ArrayQuery::query($page, [ 'title' => static function (array $page) {
    return $page['header']['title'];
} ]) === [ 
    'title' => 'Home', 
];

$page = [ 'route' => '/home' ];

ArrayQuery::query($page, [ 'route' => static function (array $page) {
    return 'https://...' . $page['route'];
} ]) === [ 
    'route' => 'https://.../home', 
];

$pages = [
    [
        'route' => '/home',
        'title' => 'Home'
    ],
    [
        'route' => '/admin',
        'title' => 'Administrative'    
    ],
];

ArrayQuery::query($pages, [ static function (array $page) {
    return array_combine(
        array_column($page, 'route'),
        array_column($page, 'title'),
    );
} ]) === [ 
    '/home'  => 'Home',
    '/admin' => 'Administrative'
];