1. Go to this page and download the library: Download jgswift/qinq 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/ */
$integers = new qinq\Collection(range(1,50));
$names = new qinq\Collection(['bob','joe','sam','john','jake']);
// Retrieve all integers divisible by 5
foreach($integers->where(function($n) { return $n % 5 === 0; }) as $integer) {
// 5, 10, 15, 20 ...
}
// Retrieve all names with a character length of 3
foreach($names->where(function($n) { return strlen($n) === 3; }) as $name) {
// bob, joe, sam
}
foreach($numbers
->filter(function($v) {
return (bool)($v & 1); // filter out even values
})
->map(function($v) {
return $v * $v * $v; // cube all remaining odd values
}) as $number) {
// 1, 27, 125, 343, 729 ...
}
// Retrieves all integers in descending order
foreach($integers->order(qinq\Order::DESCENDING) as $integer) {
// 50, 49, 48, 47 ...
}
// Retrieves all names in order of character length
foreach($names->order(function($n) { return strlen($n); } ) as $name ) {
// john, jake, bob ...
}
// Retrieve all names in order of character length (with compare function)
foreach($names->sort(function($a,$b) { return (strlen($a) > strlen($b)) ? -1 : 1; } ) as $name ) {
// john, jake, bob ...
}
// Group values by divisibility of 2
foreach($integers->group(function($n) { return $n % 2; }) as $group) {
// [ 2, 4, 6, 8 ... ], [ 1, 3, 5, 7 ... ]
}
// Group names by to character length
foreach($names->group(function($n) { return strlen($n); }) as $group) {
// [ bob, joe, sam ], [ john, jake ]
}
// Join integer collections using comparison method (on) and output method (to)
foreach($integers
->join($integers)
->on(function($outer,$inner) {
return ($outer >= $inner) ? true : false;
})
->to(function($outer,qinq\Collection $innerGroup) {
return $outer.':'.implode(',',$innerGroup->toArray());
}) as $integer ) {
// 1:1 , 2:1,2 , 3:1,2,3 ...
}
// Join integer and name collection, grouping names with integer that matches the character length
foreach($integers
->join($names)
->on(function($outer) {
return $outer;
}, 'strlen')
->to(function($outer,$inner) {
return $outer.':'.$inner;
}) as $number ) {
// 3:bob, 3:joe, 3:sam, 4:john, 4:jake
}
class User {
public $name, $email;
function __construct($name, $email) { /* ... */ }
}
$users = new qinq\Collection([
new User('bob','[email protected]'),
new User('jim','[email protected]'),
]);
foreach($users->pluck('email') as $email) {
// [email protected], [email protected]
}
foreach($integers
->from([3,4])
as $number) {
// 3, 4
}
foreach($integers
->from(3,4,5)
as $number) {
// 3, 4, 5
}