Maria Asghar Maria Asghar - 2 months ago 7
PHP Question

php array data into list items

I have an array data that shows data, but I want to use it in list items e.g.

ul
and
li
tags but I don't know the exact way how can I do it here is the sample that I want may be using
while
or
foreach
loop

<ul>
<li>Demo Item 1</li>
<li>Demo Description 1</li>
<li>http://demo-site.com/1</li>
</ul>

<ul>
<li>Demo Item 2</li>
<li>Demo Description 2</li>
<li>http://demo-site.com/2</li>
</ul>

<ul>
<li>Demo Item 3</li>
<li>Demo Description 3</li>
<li>http://demo-site.com/3</li>
</ul>

<ul>
<li>Demo Item 4</li>
<li>Demo Description 4</li>
<li>http://demo-site.com/4</li>
</ul>

<ul>
<li>Demo Item 5</li>
<li>Demo Description 5</li>
<li>http://demo-site.com/5</li>
</ul>


Here is my php code:

<?php
include_once('simple_html_dom.php');
$xml = simplexml_load_file('http://mywebsite-addr/stats.xml');
$parsed_results_array = array();
foreach($xml as $entry) {
foreach($entry->match as $item) {
// $parsed_results_array[] = json_decode(json_encode($item), true);
$items['title'] = (string) $item->opponent->name;
$items['description'] = (string) $item->result;
$items['link'] = (string) $item->url;
$items['time'] = (string) $item->date;
$parsed_results_array[] = $items;
}
}

echo '<pre>';
print_r($parsed_results_array);
echo '</pre>';
?>


Here is the array data that may help you

Array
(
[0] => Array
(
[title] => Demo Item 1
[description] => Demo Description 1
[link] => http://demo-site.com/1
[time] => Wed 15 Jun 2016, 11:30 PM EDT
)

[1] => Array
(
[title] => Demo Item 2
[description] => Demo Description 2
[link] => http://demo-site.com/2
[time] => Wed 15 Jun 2016, 10:00 PM EDT
)

[2] => Array
(
[title] => Demo Item 3
[description] => Demo Description 3
[link] => http://demo-site.com/4
[time] => Wed 15 Jun 2016, 12:45 AM EDT
)

[3] => Array
(
[title] => Demo Item 4
[description] => Demo Description 4
[link] => http://demo-site.com/4
[time] => Tue 14 Jun 2016, 11:45 PM EDT
)

[4] => Array
(
[title] => Demo Item 5
[description] => Demo Description 5
[link] => http://demo-site.com/5
[time] => Tue 14 Jun 2016, 10:00 PM EDT
)

)

Answer
foreach ( $parsed_results_array as $arrayKey => $values ) {
    echo '<ul>';
    echo '<li>' . $values['title'] . '</li>';
    echo '<li>' . $values['description'] . '</li>';
    echo '<li>' . $values['link'] . '</li>';
    echo '</ul>';
}
Comments