PHP code example of korriganmaster / lite-collection
1. Go to this page and download the library: Download korriganmaster/lite-collection 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/ */
korriganmaster / lite-collection example snippets
use Korriganmaster\LiteCollection\LiteCollection;
use Korriganmaster\LiteCollection\Storage\SqliteStorage;
// Create in-memory storage
$storage = new SqliteStorage();
$collection = new LiteCollection($storage);
// Add items
$collection[] = ['id' => 1, 'name' => 'Item 1'];
$collection[] = ['id' => 2, 'name' => 'Item 2'];
// Access items
echo $collection[0]['name']; // "Item 1"
// Count items
echo count($collection); // 2
// Iterate over the collection
foreach ($collection as $item) {
echo $item['name'];
}
use Korriganmaster\LiteCollection\Storage\SqliteStorage;
use Korriganmaster\LiteCollection\Storage\StorageInterface;
// Create storage with a custom primary key
$storage = new SqliteStorage(
StorageInterface::MODE_ASSOCIATIVE,
'custom_id'
);
$storage->insert(['custom_id' => 100, 'name' => 'Item 100']);
// Access by custom key
$item = $storage->findById(100);
// Create disk storage
$storage = new SqliteStorage(
StorageInterface::MODE_NORMAL,
'id',
'path/to/database.sqlite'
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.