1. Go to this page and download the library: Download alexandre-daubois/poq 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/ */
alexandre-daubois / poq example snippets
$cities = [
new City('Lyon', [
new Person([
new Child('Hubert', age: 30),
new Child('Aleksandr', age: 18),
new Child('Alexandre', age: 26),
new Child('Alex', age: 25),
], height: 181),
new Person([
new Child('Fabien', age: 23),
new Child('Nicolas', age: 8),
], height: 176),
new Person([
new Child('Alexis', age: 33),
new Child('Pierre', age: 5),
], height: 185)
], minimalAge: 21),
new City('Paris', [
new Person([
new Child('Will', age: 33),
new Child('Alix', age: 32),
new Child('Alan', age: 45),
], height: 185)
], minimalAge: 45)
];
use ObjectQuery\ObjectQuery;
$query = ObjectQuery::from($this->cities, 'city');
use ObjectQuery\ObjectQuery;
use ObjectQuery\ObjectQueryOrder;
$query = (ObjectQuery::from($this->cities))
->orderBy(ObjectQueryOrder::Ascending, 'name');
use ObjectQuery\ObjectQuery;
$query = ObjectQuery::from($this->cities);
// Skip the 2 first cities of the collection and fetch the rest
$query->offset(2)
->select();
// Unset any offset, no data will be skipped
$query->offset(null)
->select();
use ObjectQuery\ObjectQuery;
$query = ObjectQuery::from($this->cities);
// Only the first 2 results will be fetched by the `select` operation
$query->limit(2)
->select();
// Unset any limitation, all matching results will be used in the `select` operations
$query->limit(null)
->select();
use ObjectQuery\ObjectQuery;
$query = ObjectQuery::from($this->cities);
// Retrieve the whole object
$query->select();
// Retrieve one field
$query->select('name');
// Retrieve multiple fields
$query->select(['name', 'minimalAge']);
use ObjectQuery\Exception\NonUniqueResultException;
$query = (ObjectQuery::from($this->cities, 'city'))
->where(fn($city) => $city->name === 'Lyon');
try {
$city = $query->selectOne(); // $city is an instance of City
// You can also query a precise field
$cityName = $query->selectOne('name'); // $cityName is a string
} catch (NonUniqueResultException) {
// ...
}