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",
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()