Пример #1
0
}
if ($success) {
    echo "Success!\n\n";
    echo "Value Map Internals -- \n\n";
    var_dump($valueMap->getKeys());
    echo "\n";
    var_dump($valueMap->getValues());
    echo "\n";
} else {
    echo "Failure...\n";
}
echo "    Merge -> ";
$success = true;
$testMergeMap1 = $testMergeMap2 = $mergedMap = null;
try {
    $testMergeMap1 = new Types\Map(array('TESTMERGEKEY1' => 'TESTMERGEVALUE1', 'TESTMERGEKEY2' => 'TESTMERGEVALUE2'), array('strict' => true));
    $testMergeMap2 = new Types\Map(array('TESTMERGEKEY2' => 'NEWTESTMERGEVALUE2', 'TESTMERGEKEY3' => 'TESTMERGEVALUE2'), array('strict' => true));
    $mergeMap = Types\Map::merge($testMergeMap1, $testMergeMap2);
} catch (\Exception $e) {
    $success = false;
}
if ($success) {
    echo "Success!\n\n";
    echo "Merged Map Internals -- \n\n";
    var_dump($mergeMap->getKeys());
    echo "\n";
    var_dump($mergeMap->getValues());
    echo "\n";
} else {
    echo "Failure...\n";
}
Пример #2
0
 /**
  * Merge two or more Maps, just like array_merge
  * 
  * @static
  * 
  * @param $maps,... A variable number of arguments, all to merge
  * 
  * @return Map
  * 
  * @throws Falcraft\Data\TypesException\InvalidArgumentException
  *              if less than two arguments are provided
  * 
  */
 public static function merge()
 {
     if (func_num_args() < 2) {
         throw new Exception\InvalidArgumentException('Map->merge: Merge requires 2 or more arguments');
     } else {
         $args = self::mapArgs(func_get_args());
         $result = new Map();
         foreach ($args as $val) {
             foreach ($val as $key => $ival) {
                 $result->set($key, $ival);
             }
         }
         return $result;
     }
 }