PHP code example of camelot / collection
1. Go to this page and download the library: Download camelot/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/ */
camelot / collection example snippets
$arr = [
'debug' => true,
'color' => 'blue',
'db' => [
'driver' => 'sqlite',
],
];
$bag = Bag::from($arr)
->defaults([
'debug' => false,
'color' => 'green',
])
->replace([
'color' => 'red',
])
;
$bag->get('debug'); // true
$bag->getPath('db/driver'); // "sqlite"
$bag->keys()->join(', '); // "debug, color, db"
$bag->isAssociative(); // true
$colors = MutableBag::of('red', 'blue', 'yellow')
->merge(['green', 'orange'])
;
$colors->isIndexed(); // true
$colors->indexOf('yellow'); // 2
$colors[2]; // "yellow"
$colors->prepend('purple');
$colors[] = 'pink';
$colors->first(); // "purple"
$colors->last(); // "pink"
$colors->shuffle()->first(); // one of the colors
$colors->chunk(2); // Bags represented as arrays:
// [ ['purple', 'red'], ['blue', 'yellow'], ['green, 'orange'], ['pink'] ]
$colors->removeFirst(); // "purple"
$colors->removeFirst(); // "red"