PHP code example of taq / phpr
1. Go to this page and download the library: Download taq/phpr 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/ */
taq / phpr example snippets
$t = new PHPR\Collection([0 => "zero", 1 => "one", 2 => "two"]);
// outputs:
// null
// yay, no more 'undefined index' messages!
echo $t[10]."\n";
// outputs:
// zero
// one
// two
$t->each(function($e) {
echo "$e\n";
});
// each
// outputs:
// 0 - zero
// 1 - one
// 2 - two
$t->each(function($key, $val) {
echo "$key - $val\n";
});
$t->ero"
// }
$selected = $t->select(function($e) {
return strlen($e) > 3;
});
var_dump($selected->values());
// map
// outputs:
// array(3) {
// [0] =>
// string(4) "orez"
// [1] =>
// string(3) "eno"
// [2] =>
// string(3) "owt"
// }
$changed = $t->map(function($e) {
return strrev($e);
});
var_dump($changed->values());
$t->all(function($e) { return strlen($e) > 2; })); // true
$t->all(function($e) { return strlen($e) > 3; })); // false
$t->any(function($e) { return strlen($e) > 3; })); // true
$t->any(function($e) { return strlen($e) > 4; })); // false
// chainable methods
// outputs:
// array(2) {
// [0] =>
// string(3) "eno"
// [1] =>
// string(3) "owt"
// }
$changed = self::$_col->map(function($e) {
return strrev($e);
})->select(function($e) { return strlen($e) <= 3; });
var_dump($changed->values());