I have 2 arrays – one array is coming from the database, another from external json:
$album = array( 'author' => 'John', 'id' => '1', 'title' => 'great trip', 'url' => 'http://somelink/index.php?view=show&id=13');
$likes = array( 'link' => 'http://somelink/index.php?view=show&id=13', 'likes' => '30', 'name' => 'great trip');
I would like to display the number of likes in the correct album.
What is the best way to do it?
Thanks!
Since your question is somewhat vague, I’ll say that in general, the easiest way to merge two arrays on a specific common element is to use the common element as key:
$merged[$element['id']]can only exist once, so you can use it to merge the two arrays.