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",
- I want sort them by key
- Add keys from second array which are not in the first
- 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()andksort()Example:
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
foreachloop orimplode()