1. Go to this page and download the library: Download irfantoor/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/ */
$debug_level = $app->get('debug.level');
# returns the value stored against this identifier or returns 0 if the identifier
# is not present in the collection
$debug_log_level = $app->get('debug.log.level', 0);
$debug_level = $app['debug.level'];
# returns the value stored against this identifier or returns 0 if the identifier
# is not present in the collection
$debug_log_level = $app['debug.log.level'] ?? 0;
if ($app->has('debug.level')) {
# this will be executed even if the given identifier has the value NULL, 0
# or false
echo 'debug.level is present in the collection'
}
if (isset($app['debug.level']) {
# this will be executed even if the given identifier has the value NULL, 0
# or false
echo 'debug.level is present in the collection'
}
# using method remove
$app->remove('debug.level');
# using unset
unset($app['debug.level']);
$array = $app->toArray();
$ids_array = $app->keys();
# will return 2 for the Collection defined in initialization section
$count = $app->count();
foreach($app->toArray() as $k => $v)
{
print_r([$k => $v]);
}
foreach($app as $k => $v)
{
print_r([$k => $v]);
}
$config = new IrfanTOOR\Collection([
'app' => [
'name' => 'My App',
'version' => '1.1',
],
'debug' => [
'level' => 1,
'log' => [
'enabled' => 0,
'channel' => 'DEBUG',
'file' => '/tmp/debug.log',
],
]
]);
$config->lock();
# will not modify the values
$config->set('debug.level', 0);
$config->set('app.version', '1.2');
# will not remove the value
$config->remove('debug.log');
$callback = function ($key, $value) {
return $value * $value;
};
# int is the collection from previous example
$int2 = $int->map($callback); # 1, 4, 9, 16