EnexoOnoma
EnexoOnoma

Reputation: 8836

How to merge two arrays by creating a new array and print the result ? (with codes)

I get the contents of rss feeds, but for my bad luck they have different structure. With the help of the community I got over this problem though.

My question is how can I combine $entries1 and $entries2 into $entries3 ? What I will achieve is to handle and sort all feeds with different structure.

Thank you.

FIRST CODE

<?php
$feeds1 = array('','','');
$entries1 = array();
foreach ($feeds1 as $feed1) {
    $xml = simplexml_load_file($feed1);
    $entries1 = array_merge($entries1, $xml->xpath('/rss/channel//item'));
} 
echo "<pre>"; print_r($entries1); echo"</pre>";
?>

Upvotes: 2

Views: 124

Answers (1)

Brian Patterson
Brian Patterson

Reputation: 1625

To answer your question, I believe you would simply use array_merge() ...

$entries3 = array_merge($entries1, $entries2);

or even

$entries6 = array_merge($entries1, $entries2, $entries3, $entries4, $entries5);

or am I just not understanding this question?

Upvotes: 3

Related Questions