@@ 3-28 (lines=26) @@ | ||
1 | <?php |
|
2 | ||
3 | if (!function_exists('get')) { |
|
4 | /** |
|
5 | * Get an item from an array using "dot" notation. |
|
6 | * |
|
7 | * @param array $array |
|
8 | * @param string $key |
|
9 | * @param mixed $default |
|
10 | * @return mixed |
|
11 | */ |
|
12 | function get($array, $key, $default = null) |
|
13 | { |
|
14 | if (is_null($key)) { |
|
15 | return $array; |
|
16 | } |
|
17 | if (isset($array[$key])) { |
|
18 | return $array[$key]; |
|
19 | } |
|
20 | foreach (explode('.', $key) as $segment) { |
|
21 | if (!array_key_exists_safe($segment, $array)) { |
|
22 | return value($default); |
|
23 | } |
|
24 | $array = $array[$segment]; |
|
25 | } |
|
26 | return $array; |
|
27 | } |
|
28 | } |
|
29 | ||
30 | if (!function_exists('set')) { |
|
31 | /** |
|
@@ 114-139 (lines=26) @@ | ||
111 | } |
|
112 | } |
|
113 | ||
114 | if (!function_exists('array_get')) { |
|
115 | /** |
|
116 | * Get an item from an array using "dot" notation. |
|
117 | * |
|
118 | * @param array $array |
|
119 | * @param string $key |
|
120 | * @param mixed $default |
|
121 | * @return mixed |
|
122 | */ |
|
123 | function array_get($array, $key, $default = null) |
|
124 | { |
|
125 | if (is_null($key)) { |
|
126 | return $array; |
|
127 | } |
|
128 | if (isset($array[$key])) { |
|
129 | return $array[$key]; |
|
130 | } |
|
131 | foreach (explode('.', $key) as $segment) { |
|
132 | if (!array_key_exists_safe($segment, $array)) { |
|
133 | return value($default); |
|
134 | } |
|
135 | $array = $array[$segment]; |
|
136 | } |
|
137 | return $array; |
|
138 | } |
|
139 | } |
|
140 | ||
141 | /** |
|
142 | * Return an array with only integers value contained in the array passed |