PHP code example of bayfrontmedia / php-array-helpers
1. Go to this page and download the library: Download bayfrontmedia/php-array-helpers 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/ */
bayfrontmedia / php-array-helpers example snippets
composer
$array = [
[
'user_id' => 110,
'username' => 'John',
'active' => true
],
[
'user_id' => 111,
'username' => 'Jane',
'active' => true
]
];
$array = Arr::pluck($array, 'username', 'user_id');
$array = [
'user_id' => 110,
'username' => 'John',
'active' => true
];
$array = Arr::except($array, 'active');
$array = [
'John',
'Jane',
'Bob'
];
$array = Arr::exceptValues($array, 'John');
$array = [
'user_id' => 110,
'username' => 'John',
'active' => true
];
$array = Arr::only($array, 'username');
$array = [
'user_id' => 110,
'username' => 'John',
'active' => true
];
$missing = Arr::missing($array, [
'active',
'last_login'
]);
$array = [
'user_id' => 110,
'username' => 'John',
'active' => true
];
if (Arr::isMissing($array, [
'active',
'last_login'
])) {
// Do something
}
$array = [
'John',
'Jane',
'Bob'
];
$array = Arr::getRandomItems($array, 1);
$array = [
'first_name' => 'Jane',
'last_name' => 'Doe'
];
echo Arr::query($array);
$array = [
'name' => [
'John',
'Dave'
],
];
$existing_values = Arr::getAnyValues($array['name'], [
'John',
'Jane'
]);
$array = [
'name' => [
'John',
'Dave'
],
];
if (Arr::hasAnyValues($array['name'], [
'John',
'Jane'
])) {
// Do something
}
$array = [
'name' => [
'John',
'Dave'
],
];
if (Arr::hasAllValues($array['name'], [
'John',
'Jane'
])) {
// Do something
}