1. Go to this page and download the library: Download yuanqing/fi 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/ */
# set the date to a DateTime object
$collection->map(function($document) {
$date = DateTime::createFromFormat('Y-m-d', implode('-', $document->getField('date')));
return $document->setField('date', $date);
});
# filter out Documents with date 2014-01-01
$collection->filter(function($document) {
return $document->getField('date') != DateTime::createFromFormat('Y-m-d', '2014-01-01');
});
# sort by date in descending order
$collection->sort(function($document1, $document2) {
return $document1->getField('date') < $document2->getField('date');
});
# sets the title of all Documents to 'foo'
$collection->map(function($document) {
$document->setField('title', 'foo');
return $document;
}); #=> Collection
# filters out Documents with the title 'foo'
$collection->filter(function($document) {
return $document->getField('title') !== 'foo';
}); #=> Collection
# sorts by title in ascending order
$collection->sort(function($document1, $document2) {
return strnatcasecmp($document1->getField('title'), $document2->getField('title'));
}); #=> Collection
# sorts by title in ascending order
$collection->sort('title', Fi::ASC); #=> Collection
# sorts by title in descending order
$collection->sort('title', Fi::DESC); #=> Collection