同步和排序两个数组[关闭]

I want to synchronize two arrays.

First array:

'hi' => "Hello",
'bye'=> "Bye bye",
'w'=>"what", 

Second array:

'hi' => "Hello",
'bye'=> "Bye bye",
'we'=>"where",
'w'=>"what",
  1. I want sort them by key
  2. Add keys from second array which are not in the first
  3. Display the array

Like here they are sorted by key (abc..):

'bye'=> "Bye bye",
'hi' => "Hello",
'w'=>"what", 
'we'=>"where",

How can I do this?

I believe you're looking for array_merge() and ksort()

Example:

$array1 = array(
    'hi' => "Hello",
    'bye'=> "Bye bye",
    'w'=>"what",
);

$array2 = array(
    'hi' => "Hello",
    'bye'=> "Bye bye",
    'we'=>"where",
    'w'=>"what",
);

$array3 = array_merge($array1, $array2);
ksort($array3);

See it in action here: http://codepad.org/D2piffFE.

As far as your #3 goes, "display the array", that's completely up to you. Use a foreach loop or implode()