PHP code example of braincrafted / arrayquery

1. Go to this page and download the library: Download braincrafted/arrayquery 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/ */

    

braincrafted / arrayquery example snippets


// Select the name of all of Ned's children older than 10.
$query = $qb->create()
    ->select('name')
    ->from([
        [ 'name' => 'Robb',   'age' => 15 ],
        [ 'name' => 'Sansa',  'age' => 11 ],
        [ 'name' => 'Arya',   'age' => 9 ],
        [ 'name' => 'Bran',   'age' => 7 ],
        [ 'name' => 'Rickon', 'age' => 3 ]
    ])
    ->where('age', 10, '>');
$result = $query->findAll();



use Braincrafted\ArrayQuery\ArrayQuery;
use Braincrafted\ArrayQuery\SelectEvaluation;
use Braincrafted\ArrayQuery\WhereEvaluation;
use Braincrafted\ArrayQuery\Operator\EqualOperator

$query = new ArrayQuery(
    new SelectEvaluation,
    (new WhereEvaluation)->addOperator(new EqualOperator)
);



use Braincrafted\ArrayQuery\QueryBuilder;

$qb = new QueryBuilder;
$query = $qb->create();

$query->select('*');

$query->select('name');

$query->select([ 'name', 'age' ]);
   
$query->select('name', 'trim');
$query->select([ 'name' => 'trim', 'bio' => 'trim' ]);

$query->select('name', [ 'trim', 'upper' ]);
    $query->select(
        [
            'name' => [ 'trim', 'upper' ],
            'bio' => [ 'trim', 'upper' ]
        ]
    );

$thorinsCompany = [
    [ 'name' => 'Bilbo Baggins', 'race' => 'Hobbit' ],
    [ 'name' => 'Gandalf', 'race' => 'Wizard' ],
    [ 'name' => 'Thorin Oakenshild', 'race' => 'Dwarf' ],
    [ 'name' => 'Balin', 'race' => 'Dwarf'],
    [ 'name' => 'Bifur', 'race' => 'Dwarf'],
    // ...
];

$query->from($thorinsCompany);

$query->where('race', 'Dwarf');

$query->where('age', 50, '>');
   
$query->where('name', 'foo', '=', 'trim');
$query->where('name', 'foo', '=', [ 'trim', 'strtolower' ]);

$query->where('name', 'nerd', '=', 'replace 3,e');

$results = $query->findAll();
// [ [ 'name' => 'Balin' ], [ 'name' => 'Bifur' ], ... ]

$result = $query->findOne();
// [ 'name' => 'Gandalf' ]

$result = $query->findScalar();
// [ 'Balin', 'Bifur', 'Bofur', ... ]

$result = $query->findOneScalar()
// 'Gandalf'