How to collect array indexes from different resources?
How to collect array indexes from different resources?
I get data from 2 different URLs, But sometimes both have the same data.
I only want to save the data in an array when the data is the same.
Getting the data from first website:
$a = 'http://firstwebsite.com';
$rss = simplexml_load_file($a);
foreach ($rss->channel->item as $item) {
$post['title'] = $item->title;
$post['link'] = $item->link;
$post['date'] = $item->pubDate;
$post['description'] = $item->description;
$articles = $post;
}
So that if I print the articles array:
echo '<pre>';
print_r($articles);
echo '</pre>';
I get:
Array
(
[0] => Array
(
[title] => SimpleXMLElement Object
(
[0] => First Item Title
)
[link] => SimpleXMLElement Object
(
[0] => http://firstitemlink.com
)
[date] => SimpleXMLElement Object
(
[0] => 18 Jun 2018 06:52:20
)
[description] => SimpleXMLElement Object
(
[0] => SimpleXMLElement Object
(
)
)
)
[1] => Array
(
[title] => SimpleXMLElement Object
(
[0] => Second Item Title
)
[link] => SimpleXMLElement Object
(
[0] => http://seconditemlink.com
)
[date] => SimpleXMLElement Object
(
[0] => 18 May 2018 12:03:03
)
[description] => SimpleXMLElement Object
(
[0] => SimpleXMLElement Object
(
)
)
)
)
Then the second website:
$b = 'http://secondwebsite.com';
$rss = simplexml_load_file($b);
foreach ($rss->channel->item as $item) {
$post['title'] = $item->title;
$post['link'] = $item->img;
$articles = $post;
}
The number of posts may vary from the 2 websites.
I want to get an array with the (title, link, description, pubDate and img), When the title is the same in both the arrays.
So that the final array would be:
Array
(
[0] => Array
(
[title] => SimpleXMLElement Object
(
[0] => First Item Title
)
[link] => SimpleXMLElement Object
(
[0] => http://firstitemlink.com
)
[date] => SimpleXMLElement Object
(
[0] => 18 Jun 2018 06:52:20
)
[description] => SimpleXMLElement Object
(
[0] => SimpleXMLElement Object
(
)
)
[img] => SimpleXMLElement Object
(
[0] => Post Img.
)
)
)
I can get all the data, But I can't all the same post data together.
I can run each in a separate function or in the same function.
I want to save this data in a database, So if there is a better way it would be great.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.