1. Go to this page and download the library: Download reptily/array-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/ */
reptily / array-list example snippets
function show(array $items)
{
foreach ($items as $item) {
echo $item->id . PHP_EOL;
}
}
function show(ArrayList $items)
{
foreach ($items as $item) {
echo $item->id . PHP_EOL;
}
}
$list = new ArrayList(ArrayList::TYPE_INTEGER, [1, 2, 3]);
// or
$list = new ArrayListInteger([1, 2, 3]);
foreach ($list as $item) {
echo $item . PHP_EOL;
}
class UserList extends ArrayList {
public function __construct(?array $items = null)
{
parent::__construct(UserDTO::class, $items);
}
};
class UserDTO {
public $id;
public $name;
public function __construct($id, $name)
{
$this->id = $id;
$this->name = $name;
}
}
$userList = new UserList();
$userList->add(new UserDTO(1, 'bob'));
$userList->add(new UserDTO(2, 'job'));
function echoDTOs(UserList $list): void
{
$list->forEach(function ($item) {
echo sprintf("id:%d name:%s" . PHP_EOL, $item->id, $item->name);
});
}
$ids = new ArrayListInteger([1, 2, 3]);
$ids->add(4);
function show(ArrayListInteger $ids)
{
$ids->forEach(function($id) {
echo $id . PHP_EOL;
});
}
show();
$ids = new ArrayListInteger([1, 2, 3]);
$ids[] = 4;
function show(ArrayListInteger $ids)
{
foreach ($ids as $id) {
echo $id;
}
}
show();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.