在php中合并2个数组

Wyc*_*yck 1 php arrays merge

这看起来很简单,但我无法弄清楚.我需要为2个数组返回一个数组合并,它们不完全相同,一个是全局多维数组.

global $animals;

$array1 = array('dogs' => __('Dogs'), 'cats' => __('Cats'));  //localized
$array2 = $animals;  //not localized

the var_dump of $array2 is:

array
  'ducks' => 
    array
      'width' => int 350
      'height' => int 350
      'crop' => boolean true
  'cows' => 
    array
      'width' => int 750
      'height' => int 150
      'crop' => boolean true
Run Code Online (Sandbox Code Playgroud)

我需要$merge = array_merge($array1, $array2);返回这样的数组.

array('dogs' => __('Dogs'), 'cats' => __('Cats'), 'ducks', 'cows');  
Run Code Online (Sandbox Code Playgroud)

但我得到了各种奇怪的结果.

小智 6

试试这个:

$merge = array_merge($array1, array_keys($array2));
Run Code Online (Sandbox Code Playgroud)