1. Go to this page and download the library: Download derheyne/laravel-list 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/ */
derheyne / laravel-list example snippets
use dhy\LaravelList\ListCollection;
$list = new ListCollection(['a', 'b', 'c']);
$list->filter(fn ($v) => $v !== 'b')->toJson();
// "[\"a\",\"c\"]" -- a JSON array, even after filtering
$c = collect(['a', 'b', 'c'])->filter(fn ($v) => $v !== 'b');
$c->all(); // [0 => 'a', 2 => 'c'] -- gap at index 1
$c->toJson(); // {"0":"a","2":"c"} -- JSON object, not array
$c[1]; // null -- unexpected
$list = new ListCollection(['a', 'b', 'c', 'd']);
$list->forget(1); // remove by index, re-indexes: [a, c, d]
$list->forget([0, 2]); // remove multiple indices at once
$list->pull(1); // remove and return the value, re-indexes
$list->prepend('z'); // always adds to the beginning (the $key argument is ignored)
$list->push('x');
$list->shift();
$list->pop();
$list->splice(1, 1, ['X']); // remove and replace, re-indexes
$list = new ListCollection([1, 2, 3]);
$list->filter(fn ($v) => $v > 1)->toJson(); // "[2,3]"
// A standard Collection produces an object after the same filter:
collect([1, 2, 3])->filter(fn ($v) => $v > 1)->toJson(); // "{\"1\":2,\"2\":3}"