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