$customers = [ (object) [ 'name' => 'John Smith', 'last_purchase' => '2020-01-01' ], (object) [ 'name' => 'Jane Doe', 'last_purchase' => '2021-01-01' ], (object) [ 'name' => 'Bob Johnson', 'last_purchase' => '2021-02-01' ] ]; use ObjectSelect\ObjectSelect; $filtered_customers = ObjectSelect::fromArray($customers) ->where('last_purchase', '<', date('Y-m-d', strtotime('-6 months'))) ->execute(); // Output filtered customers foreach ($filtered_customers as $customer) { echo $customer->name . ' has not made a purchase in more than six months.' . PHP_EOL; }
$books = [ (object) [ 'title' => '1984', 'author' => 'George Orwell', 'year' => 1949 ], (object) [ 'title' => 'Brave New World', 'author' => 'Aldous Huxley', 'year' => 1932 ], (object) [ 'title' => 'Animal Farm', 'author' => 'George Orwell', 'year' => 1945 ] ]; use ObjectSelect\ObjectSelect; $sorted_books = ObjectSelect::fromArray($books) ->orderBy('year', 'desc') ->execute(); // Output sorted books foreach ($sorted_books as $book) { echo $book->title . ' by ' . $book->author . ' was published in ' . $book->year . PHP_EOL; }The PHP Object Select library can be found at https://github.com/cweiske/object-select.