Mercurial > hg > isophonics-drupal-site
comparison vendor/zendframework/zend-stdlib/src/ArrayUtils.php @ 12:7a779792577d
Update Drupal core to v8.4.5 (via Composer)
author | Chris Cannam |
---|---|
date | Fri, 23 Feb 2018 15:52:07 +0000 |
parents | 4c8ae668cc8c |
children | c2387f117808 |
comparison
equal
deleted
inserted
replaced
11:bfffd8d7479a | 12:7a779792577d |
---|---|
37 * @param bool $allowEmpty Should an empty array() return true | 37 * @param bool $allowEmpty Should an empty array() return true |
38 * @return bool | 38 * @return bool |
39 */ | 39 */ |
40 public static function hasStringKeys($value, $allowEmpty = false) | 40 public static function hasStringKeys($value, $allowEmpty = false) |
41 { | 41 { |
42 if (!is_array($value)) { | 42 if (! is_array($value)) { |
43 return false; | 43 return false; |
44 } | 44 } |
45 | 45 |
46 if (!$value) { | 46 if (! $value) { |
47 return $allowEmpty; | 47 return $allowEmpty; |
48 } | 48 } |
49 | 49 |
50 return count(array_filter(array_keys($value), 'is_string')) > 0; | 50 return count(array_filter(array_keys($value), 'is_string')) > 0; |
51 } | 51 } |
57 * @param bool $allowEmpty Should an empty array() return true | 57 * @param bool $allowEmpty Should an empty array() return true |
58 * @return bool | 58 * @return bool |
59 */ | 59 */ |
60 public static function hasIntegerKeys($value, $allowEmpty = false) | 60 public static function hasIntegerKeys($value, $allowEmpty = false) |
61 { | 61 { |
62 if (!is_array($value)) { | 62 if (! is_array($value)) { |
63 return false; | 63 return false; |
64 } | 64 } |
65 | 65 |
66 if (!$value) { | 66 if (! $value) { |
67 return $allowEmpty; | 67 return $allowEmpty; |
68 } | 68 } |
69 | 69 |
70 return count(array_filter(array_keys($value), 'is_int')) > 0; | 70 return count(array_filter(array_keys($value), 'is_int')) > 0; |
71 } | 71 } |
84 * @param bool $allowEmpty Should an empty array() return true | 84 * @param bool $allowEmpty Should an empty array() return true |
85 * @return bool | 85 * @return bool |
86 */ | 86 */ |
87 public static function hasNumericKeys($value, $allowEmpty = false) | 87 public static function hasNumericKeys($value, $allowEmpty = false) |
88 { | 88 { |
89 if (!is_array($value)) { | 89 if (! is_array($value)) { |
90 return false; | 90 return false; |
91 } | 91 } |
92 | 92 |
93 if (!$value) { | 93 if (! $value) { |
94 return $allowEmpty; | 94 return $allowEmpty; |
95 } | 95 } |
96 | 96 |
97 return count(array_filter(array_keys($value), 'is_numeric')) > 0; | 97 return count(array_filter(array_keys($value), 'is_numeric')) > 0; |
98 } | 98 } |
117 * @param bool $allowEmpty Is an empty list a valid list? | 117 * @param bool $allowEmpty Is an empty list a valid list? |
118 * @return bool | 118 * @return bool |
119 */ | 119 */ |
120 public static function isList($value, $allowEmpty = false) | 120 public static function isList($value, $allowEmpty = false) |
121 { | 121 { |
122 if (!is_array($value)) { | 122 if (! is_array($value)) { |
123 return false; | 123 return false; |
124 } | 124 } |
125 | 125 |
126 if (!$value) { | 126 if (! $value) { |
127 return $allowEmpty; | 127 return $allowEmpty; |
128 } | 128 } |
129 | 129 |
130 return (array_values($value) === $value); | 130 return (array_values($value) === $value); |
131 } | 131 } |
159 * @param bool $allowEmpty Is an empty array() a valid hash table? | 159 * @param bool $allowEmpty Is an empty array() a valid hash table? |
160 * @return bool | 160 * @return bool |
161 */ | 161 */ |
162 public static function isHashTable($value, $allowEmpty = false) | 162 public static function isHashTable($value, $allowEmpty = false) |
163 { | 163 { |
164 if (!is_array($value)) { | 164 if (! is_array($value)) { |
165 return false; | 165 return false; |
166 } | 166 } |
167 | 167 |
168 if (!$value) { | 168 if (! $value) { |
169 return $allowEmpty; | 169 return $allowEmpty; |
170 } | 170 } |
171 | 171 |
172 return (array_values($value) !== $value); | 172 return (array_values($value) !== $value); |
173 } | 173 } |
185 * @param int|bool $strict | 185 * @param int|bool $strict |
186 * @return bool | 186 * @return bool |
187 */ | 187 */ |
188 public static function inArray($needle, array $haystack, $strict = false) | 188 public static function inArray($needle, array $haystack, $strict = false) |
189 { | 189 { |
190 if (!$strict) { | 190 if (! $strict) { |
191 if (is_int($needle) || is_float($needle)) { | 191 if (is_int($needle) || is_float($needle)) { |
192 $needle = (string) $needle; | 192 $needle = (string) $needle; |
193 } | 193 } |
194 if (is_string($needle)) { | 194 if (is_string($needle)) { |
195 foreach ($haystack as &$h) { | 195 foreach ($haystack as &$h) { |
213 * @throws Exception\InvalidArgumentException if $iterator is not an array or a Traversable object | 213 * @throws Exception\InvalidArgumentException if $iterator is not an array or a Traversable object |
214 * @return array | 214 * @return array |
215 */ | 215 */ |
216 public static function iteratorToArray($iterator, $recursive = true) | 216 public static function iteratorToArray($iterator, $recursive = true) |
217 { | 217 { |
218 if (!is_array($iterator) && !$iterator instanceof Traversable) { | 218 if (! is_array($iterator) && ! $iterator instanceof Traversable) { |
219 throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable object'); | 219 throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable object'); |
220 } | 220 } |
221 | 221 |
222 if (!$recursive) { | 222 if (! $recursive) { |
223 if (is_array($iterator)) { | 223 if (is_array($iterator)) { |
224 return $iterator; | 224 return $iterator; |
225 } | 225 } |
226 | 226 |
227 return iterator_to_array($iterator); | 227 return iterator_to_array($iterator); |
272 if ($value instanceof MergeReplaceKeyInterface) { | 272 if ($value instanceof MergeReplaceKeyInterface) { |
273 $a[$key] = $value->getData(); | 273 $a[$key] = $value->getData(); |
274 } elseif (isset($a[$key]) || array_key_exists($key, $a)) { | 274 } elseif (isset($a[$key]) || array_key_exists($key, $a)) { |
275 if ($value instanceof MergeRemoveKey) { | 275 if ($value instanceof MergeRemoveKey) { |
276 unset($a[$key]); | 276 unset($a[$key]); |
277 } elseif (!$preserveNumericKeys && is_int($key)) { | 277 } elseif (! $preserveNumericKeys && is_int($key)) { |
278 $a[] = $value; | 278 $a[] = $value; |
279 } elseif (is_array($value) && is_array($a[$key])) { | 279 } elseif (is_array($value) && is_array($a[$key])) { |
280 $a[$key] = static::merge($a[$key], $value, $preserveNumericKeys); | 280 $a[$key] = static::merge($a[$key], $value, $preserveNumericKeys); |
281 } else { | 281 } else { |
282 $a[$key] = $value; | 282 $a[$key] = $value; |
283 } | 283 } |
284 } else { | 284 } else { |
285 if (!$value instanceof MergeRemoveKey) { | 285 if (! $value instanceof MergeRemoveKey) { |
286 $a[$key] = $value; | 286 $a[$key] = $value; |
287 } | 287 } |
288 } | 288 } |
289 } | 289 } |
290 | 290 |