PHP code example of lucid / phlist

1. Go to this page and download the library: Download lucid/phlist 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/ */

    

lucid / phlist example snippets




use Lucid\Phlist\Phlist;

$list = new Phlist('foo', 'bar', ...);


$list = new Phlist('foo');
$list->push('bar'); 
$list->toArray(); // => ['foo', 'bar']


$list = new Phlist(1, 2, 3);
$list->insert(1, 1.5); 
$list->toArray(); // => [1, 1.5, 2]


$list = new Phlist(1, 2, 3);
$list->pop(); // => 3


$list = new Phlist(1, 2, 3);
$list->remove(2); 
$list->toArray(); // [1, 3]


$list = new Phlist(1, 4, 3, 2);
$list->sort(); 
$list->toArray(); // [1, 2, 3, 4]

$list = new Phlist(1, 4, 3, 2);
$list->sort(function ($a, $b) {
    return $a > $b ? 1 : -1;
}); 
$list->toArray(); // [1, 2, 3, 4]



$list = new Phlist(1, 2, 3);
$list->reverse();
$list->toArray(); // =>[3, 2, 1]


$list = new Phlist(1, 2, 3, 4, 2, 5);
$list->countValue(5); // => 1
$list->countValue(2); // => 2


$listA = new Phlist('a', 'b');
$listB = new Phlist('c', 'd');
$listA->extend($listB);
$listA->toArray() // => ['a', 'b', 'c', 'd'];

php >= 7.0master