I’m newbie in PHP. I have to code the system like RSS Reader in this language. So I parsed XML files (which are RSS Feeds) and got a large array which has many sub-arrays. Since it is hard to explain what I need, I decided to add the example code.
As you see, there is an items in my large array and there are a lot of sub-array of items array, for example, [0], [1], [2], [3] and so on. (I added to the examples just 2 ones of them – [0] and [1])
Array
(
[items] => Array
(
[0] => Array
(
[title] => First title
[alternate] => Array
(
[0] => Array
(
[href] => http://example-one.com/first-title/
)
)
[contents] => Array
(
[content] => First content
)
[author] => First author
[origin] => Array
(
[htmlUrl] => http://example-one.com
)
)
[1] => Array
(
[title] => Second title
[alternate] => Array
(
[0] => Array
(
[href] => http://example-two.com/second-title/
)
)
[contents] => Array
(
[content] => Second content
)
[author] => Second author
[origin] => Array
(
[htmlUrl] => http://example-two.com
)
)
)
)
So I need to get the values of the all objects in the output and set them to the variables in the loop. For example, the output of this array must be like this:
title = First title
href = http://example-one.com/first-title/
content = First content
author = First author
htmlUrl = example-one.com
title = Second title
href = http://example-two.com/second-title/
content = Second content
author = Second author
htmlUrl = example-two.com
Since, I’m beginner in PHP, it’s hard to write the code of logic. If you have any idea for solving this problem, please answer.
Thanks in advance!
You should check this link. It tells how to deal with arrays structured like a tree. Despite it may seem a bit advanced and complicated, try to understand it. Believe me, it’s the best for you!
EDIT