PHP code example of nahid / qarray

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

    

nahid / qarray example snippets


class JsonQueryEngine extends \Nahid\QArray\QueryEngine
{
    public function readPath($path)
    {
        $data = file_get_contents($path);

        return json_decode($data, true);
    }

    public function parseData($data)
    {
        return json_decode($data, true);
    }
}

class Product
{
    protected $query;

    public function __construct(\Nahid\QArray\QueryEngine $query)
    {
        $this->query = $query;
    }

    public function getMacbook()
    {
        try {
            return $this->query
                ->from('.')
                ->where('cat', 2)
                ->get();
        } catch (\Exception $e) {
           return false;
        }

    }
}

$data = new JsonQueryEngine('data.json');
$query = new SomethingBuilder($data);

dump($query->getMacbook()->toArray());

$q = new Jsonq('data.json');
$res = $q->from('users')->where('id', '=', 1)->get();

$q = new Jsonq('data.json');
$res = $q->from('users')
->where('id', '=', 1)
->where('location', '=', 'barisal')
->get();

$q = new Jsonq('data.json');
$res = $q->from('users')
->where('id', '=', 1)
->orWhere('id', '=', 2)
->get();

array:2 [
  1 => array:4 [
    "id" => 2
    "name" => "macbook pro 2017"
    "cat" => 2
    "price" => 210000
  ]
  4 => array:4 [
    "id" => 5
    "name" => "macbook air"
    "cat" => 2
    "price" => 110000
  ]
]