當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Arrays::mergeRecursive方法代碼示例

本文整理匯總了PHP中Arrays::mergeRecursive方法的典型用法代碼示例。如果您正苦於以下問題:PHP Arrays::mergeRecursive方法的具體用法?PHP Arrays::mergeRecursive怎麽用?PHP Arrays::mergeRecursive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Arrays的用法示例。


在下文中一共展示了Arrays::mergeRecursive方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: mergeRecursive

 /**
  * This function does indeed merge arrays, but it converts values with duplicate
  * keys to arrays rather than overwriting the value in the first array with the duplicate
  * value in the second array, as array_merge does. I.e., with array_merge_recursive,
  * this happens (documented behavior):
  *
  * <code>
  * array_merge_recursive(array('key' => 'org value'), array('key' => 'new value'));
  * $result = array('key' => array('org value', 'new value'));
  * </code>
  *
  * Arrays::mergeRecursive does not change the datatypes of the values in the arrays.
  * Matching keys' values in the second array overwrite those in the first array, as is the
  * case with array_merge, i.e.:
  * <code>
  * Arrays::mergeRecursive(array('key' => 'org value'), array('key' => 'new value'));
  * $result =  array('key' => 'new value');
  * </code>
  * Parameters are passed by reference, though only for performance reasons. They're not
  * altered by this function.
  *
  * @param array $firstArray
  * @param array $secondArray
  * @return array
  * @author Daniel <daniel (at) danielsmedegaardbuus (dot) dk>
  * @author Funivan <dev (at) funivan (dot) com>
  */
 public static function mergeRecursive(array $firstArray, array $secondArray)
 {
     $merged = $firstArray;
     foreach ($secondArray as $key => $value) {
         if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
             $merged[$key] = Arrays::mergeRecursive($merged[$key], $value);
         } else {
             $merged[$key] = $value;
         }
     }
     return $merged;
 }
開發者ID:ukrcms,項目名稱:ukrcms,代碼行數:39,代碼來源:Arrays.php


注:本文中的Arrays::mergeRecursive方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。