PHP code example of wake / php-array-kit
1. Go to this page and download the library: Download wake/php-array-kit 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/ */
wake / php-array-kit example snippets
$input = [
['id' => 'A', 'title' => 'A apple', 'value' => 10],
['id' => 'B', 'title' => 'B bear', 'value' => 27],
['id' => 'C', 'title' => 'C Cat', 'value' => 10],
];
// Split array base on key
$output = keyi ($input, 'id');
/*
[
'A' => ['id' => 'A', 'title' => 'A apple', 'value' => 10],
'B' => ['id' => 'B', 'title' => 'B bear', 'value' => 27],
'C' => ['id' => 'C', 'title' => 'C Cat', 'value' => 10],
];
*/
// Base on multiple keys
$output = keyi ($input, ['id', 'title']);
/*
[
'A' => [
'A apple' => ['id' => 'A', 'title' => 'A apple', 'value' => 10]
],
'B' => [
'B bear' => ['id' => 'B', 'title' => 'B bear', 'value' => 27]
],
'C' => [
'C Cat' => ['id' => 'C', 'title' => 'C Cat', 'value' => 10]
],
];
*/
// Gather elements
$output = keyi ($input, 'value', true);
/*
[
'10' => [
['id' => 'A', 'title' => 'A apple', 'value' => 10],
['id' => 'B', 'title' => 'B bear', 'value' => 27],
],
'27' => [
['id' => 'C', 'title' => 'C Cat', 'value' => 10],
]
];
*/
$input = [
'A' => [
'id' => 'A',
'A apple' => [
'value' => 10
]
],
'B' => [
'id' => 'B',
'B bear' => [
'value' => 27
]
],
'C' => [
'id' => 'C',
'C Cat' => [
'value' => 10
]
],
];
// Dig value from array
$output = dig ($input, 'id');
/*
[
0 => 'A',
1 => 'B',
2 => 'C',
];
*/
// Dig deeply
$output = dig ($input, 'value', 2);
/*
[
0 => 10,
1 => 27,
2 => 10,
];
*/
json
{
"e/php-array-kit": "*"
}
}
bash
$ composer