Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
107 lines (95 loc) · 2.61 KB

File metadata and controls

107 lines (95 loc) · 2.61 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
if( !function_exists('array_flatten') ) {
/**
* Given an array, find all the values recursively.
*
* @param array $array The Array to be Flattened
* @param bool $allow_duplicates Should the array allow duplicates
* @return array The resulting array or NULL on failure
*/
function array_flatten( array $array, $allow_duplicates = false ) {
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
$final = array();
foreach( $it as $v ) {
if( $allow_duplicates ) {
$final[] = $v;
} else {
$final[$v] = $v;
}
}
return $final;
}
}
if( !function_exists('array_blend') ) {
/**
* Given an array of arrays, merges the array's children together.
*
* @param array $arrays An array of arrays.
* @param array|null $keys The merged array.
* @return array The resulting blended array
*/
function array_blend( array $arrays, array $keys = null ) {
$out = array();
foreach( $arrays as $key => $array ) {
if( is_array($array) && (is_null($keys) || (in_array($key, $keys))) ) {
foreach( $array as $value ) {
$out[] = $value;
}
}
}
return $out;
}
}
if( !function_exists('array_key_array') ) {
/**
* Given an array of similarly keyed arrays, returns an array of only the values of the key.
*
* @param array $arrays An array of similarly keyed arrays
* @param int|string $key The desired key
* @return array The flattened array
*/
function array_key_array( array $arrays, $key ) {
$out = array();
foreach( $arrays as $i => $array ) {
$out[$i] = $array[$key];
}
return $out;
}
}
if( !function_exists('array_keys_array') ) {
/**
* Given an array of similarly keyed arrays, returns an array of only the selected keys.
*
* @param array $arrays An array of similarly keyed arrays
* @param array|int|string $keys The key or array of keys to return
* @return array The array of arrays with just the selected keys
*/
function array_keys_array( array $arrays, $keys ) {
$keys = (array)$keys;
$out = array();
foreach( $arrays as $i => $array ) {
foreach( $keys as $index ) {
$out[$i][$index] = $array[$index];
}
}
return $out;
}
}
if( !function_exists('array_key_refill') ) {
/**
* Given a keyed array, fills any missing values.
*
* @param array $array A Keyed array
* @param array $keys The keys that must exist
* @param mixed $fill The desired value to fill with
* @return array
*/
function array_key_refill( array $array, array $keys, $fill = array() ) {
foreach( $keys as $key ) {
if( !isset($array[$key]) ) {
$array[$key] = $fill;
}
}
return $array;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.