This repository was archived by the owner on Dec 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
array_of_array.inc
Tadatoshi Tokutake edited this page May 30, 2015
·
13 revisions
array aoa_set(array $aoa, array $keys, mixed $value)
- Return the array set
$valueatkey1 => [key2 => ...]. - Example:
var_dump(aoa_set([], ['VAIO Z', 'spec', 'cpu'], 'Core i7-5557U 3.10 GHz'));
// => [
// 'VAIO Z' => [
// 'spec' => [
// 'cpu' => 'Core i7-5557U 3.10 GHz',
// ]
// ]
// ]array aoa_unset(array $aoa, array $keys)
- Return the array unset the value at
key1 => [key2 => ...]. - Example:
$aoa = ['db' => ['primary' => 1, 'secondary' => 2]];
var_dump(aoa_unset($aoa, ['test', 'secondary'])); // => ['db' => ['primary' => 1]]array aoa_collect(array $aoa, mixed $key)
- Return the array whose element has
$keyas key in$aoa. - Example:
$aoa = [
'main' => [
'title' => 'who am i',
'authors' => ['A'] ,
],
'subs' => [
['title' => 'who are you', 'authors' => ['B', 'C']],
['title' => 'what is it' , 'authors' => ['D' ]],
],
];
var_dump(aoa_collect($aoa, 'authors')); // => [['A'], ['B', 'C'], ['D']]array aoa_transpose(array $matrix)
- Return the transposed matrix.
- Example:
$matrix = [
[1, 2, 3],
[4, 5, 6],
];
var_dump(aoa_transpose($matrix));
// => [
// [1, 4],
// [2, 5],
// [3, 6],
// ]array aoa_values(array $aoa, mixed $key)
- Return the array which is the elements having
$keyof the array of the array. - Example:
$aoa = [['id' => 0, 'name' => 'A'], ['id' => 1, 'name' => 'B']];
var_dump(aoa_values($aoa, 'id')); // => [0, 1]mixed aoa_sum(array $aoa, mixed $key)
- Return the sum of elements having
$keyof the array of the array. - Example:
$aoa = [['id' => 0, 'point' => 2.5], ['id' => 1, 'point' => 3.5]];
var_dump(aoa_sum($aoa, 'point')); // => 6array aoa_sort(array $aoa, mixed $key, mixed $order = SORT_ASC, mixed $option = SORT_REGULAR)
- Return the array sorted by the values having
$key. - Notice: About
$orderand$option, see the document of array_multisort(). - Example:
$aoa = [['id' => 0, 'nice' => 15], ['id' => 1, 'nice' => 10]];
var_dump(aoa_sort($aoa, 'nice')); // => [['id' => 1, 'nice' => 10], ['id' => 0, 'nice' => 15]]array aoa_associate(array $aoa, mixed $key)
- Return the array having the values of
$keyas keys. - Example:
$aoa = [['id' => 0, 'name' => 'A', 'nice' => 1], ['id' => 1, 'name' => 'B', 'nice' => 15]];
var_dump(aoa_associate($aoa, 'name')); // => ['A' => ['id' => 0, 'nice' => 1], 'B' => ['id' => 1, 'nice' => 15]]Welcome any issure or pull request!
Please contact me by mail to tadatoshi.tokutake@gmail.com if you have some questions!