1. Go to this page and download the library: Download chr15k/array 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/ */
use Chr15k\Arr\Arr;
$array = [100, 200, 300];
$first = Arr::first($array, function ($value, $key) {
return $value >= 150;
});
// 200
// A default value may also be passed as the third parameter to the method. This value will be returned if no value passes the truth test:
$first = Arr::first($array, $callback, $default);
use Chr15k\Arr\Arr;
$array = ['products' => ['desk' => ['price' => 100]]];
$price = Arr::get($array, 'products.desk.price');
// 100
// The Arr::get method also accepts a default value, which will be returned if the specific key is not found:
$discount = Arr::get($array, 'products.desk.discount', 0);
// 0
use Chr15k\Arr\Arr;
$array = [100, 200, 300, 110];
$last = Arr::last($array, function ($value, $key) {
return $value >= 150;
});
// 300
// A default value may be passed as the third argument to the method. This value will be returned if no value passes the truth test:
$last = Arr::last($array, $callback, $default);
use Chr15k\Arr\Arr;
$array = [
['developer' => ['id' => 1, 'name' => 'Taylor']],
['developer' => ['id' => 2, 'name' => 'Abigail']],
];
$names = Arr::pluck($array, 'developer.name');
// ['Taylor', 'Abigail']
// You may also specify how you wish the resulting list to be keyed:
$names = Arr::pluck($array, 'developer.name', 'developer.id');
// [1 => 'Taylor', 2 => 'Abigail']
use Chr15k\Arr\Arr;
$array = ['one', 'two', 'three', 'four'];
$array = Arr::prepend($array, 'zero');
// ['zero', 'one', 'two', 'three', 'four']
// If needed, you may specify the key that should be used for the value:
$array = ['price' => 100];
$array = Arr::prepend($array, 'Desk', 'name');
// ['name' => 'Desk', 'price' => 100]
use Chr15k\Arr\Arr;
$array = ['name' => 'Desk', 'price' => 100];
$name = Arr::pull($array, 'name');
// $name: Desk
// $array: ['price' => 100]
// A default value may be passed as the third argument to the method. This value will be returned if the key doesn't exist:
$value = Arr::pull($array, $key, $default);
use Chr15k\Arr\Arr;
$array = [1, 2, 3, 4, 5];
$random = Arr::random($array);
// 4 - (retrieved randomly)
// You may also specify the number of items to return as an optional second argument.
// Note that providing this argument will return an array, even if only one item is desired:
$items = Arr::random($array, 2);
// [2, 5] - (retrieved randomly)
use Chr15k\Arr\Arr;
$array = ['Desk', 'Table', 'Chair'];
$sorted = Arr::sort($array);
// ['Chair', 'Desk', 'Table']
// Reverse the order by passing true to the second argument
$sorted = Arr::sort($array, true);
// ['Table', 'Desk', 'Chair']
use Chr15k\Arr\Arr;
$string = 'Laravel';
$array = Arr::wrap($string);
// ['Laravel']
// If the given value is null, an empty array will be returned:
$nothing = null;
$array = Arr::wrap($nothing);
// []
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.