Mercurial > hg > cmmr2012-drupal-site
comparison vendor/dflydev/dot-access-data/src/Dflydev/DotAccessData/Util.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is a part of dflydev/dot-access-data. | |
5 * | |
6 * (c) Dragonfly Development Inc. | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Dflydev\DotAccessData; | |
13 | |
14 class Util | |
15 { | |
16 /** | |
17 * Test if array is an associative array | |
18 * | |
19 * Note that this function will return true if an array is empty. Meaning | |
20 * empty arrays will be treated as if they are associative arrays. | |
21 * | |
22 * @param array $arr | |
23 * | |
24 * @return boolean | |
25 */ | |
26 public static function isAssoc(array $arr) | |
27 { | |
28 return (is_array($arr) && (!count($arr) || count(array_filter(array_keys($arr),'is_string')) == count($arr))); | |
29 } | |
30 | |
31 /** | |
32 * Merge contents from one associtative array to another | |
33 * | |
34 * @param array $to | |
35 * @param array $from | |
36 * @param bool $clobber | |
37 */ | |
38 public static function mergeAssocArray($to, $from, $clobber = true) | |
39 { | |
40 if ( is_array($from) ) { | |
41 foreach ($from as $k => $v) { | |
42 if (!isset($to[$k])) { | |
43 $to[$k] = $v; | |
44 } else { | |
45 $to[$k] = self::mergeAssocArray($to[$k], $v, $clobber); | |
46 } | |
47 } | |
48 | |
49 return $to; | |
50 } | |
51 | |
52 return $clobber ? $from : $to; | |
53 } | |
54 } |