php数组数据到列表项中
我有一个显示数据的数组数据,但我想在列表项中使用它,例如php数组数据到列表项中,php,arrays,Php,Arrays,我有一个显示数据的数组数据,但我想在列表项中使用它,例如ul和li标记,但我不知道具体的方法,我想在这里使用的示例可能是while或foreach循环 <ul> <li>Demo Item 1</li> <li>Demo Description 1</li> <li>http://demo-site.com/1</li> </ul> <ul> <li
ul
和li
标记,但我不知道具体的方法,我想在这里使用的示例可能是while
或foreach
循环
<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>
foreach($parsed\u results\u数组为$arrayKey=>$values){
回声“”;
回显“- ”.$values[“title]”。
;
回显“- ”.$values['description']。
”;
回显“- ”.$values['link']”。
;
回声“
”;
}
在不创建额外阵列的情况下尝试此操作:
include_once('simple_html_dom.php');
$xml=simplexml\u加载\u文件('http://mywebsite-addr/stats.xml');
$parsed_results_array=array();
foreach($xml作为$entry){
foreach($entry->匹配为$item){
回声“”;
回显“- ”(字符串)$item->对手->名字。“
”;
回显“- ”(字符串)$item->result.“
”;
回显“- ”(字符串)$item->url.“
”;
回声“
”;
}
}
您确实不需要这两个数组,但至少删除这一行
echo "
<ul>
<li>$items[title]</li>
<li>$items[description]</li>
<li>$items[link]</li>
</ul>
";
并将其替换为
<?php
// Some nice php code here ...
?>
<?php foreach( $parsed_results_array as $result ): ?>
<ul>
<?php foreach( $result as $data ): ?>
<li><?php echo $data ?></li>
<?php endforeach ?>
</ul>
<?php endforeach ?>
<?php
// Some other php code there ...
?>
echo”
- $items[标题]
- $items[说明]
- $items[链接]
";
模板化备选方案:
我们不是免费的编码服务,请向我们展示您为获得所需输出所做的尝试,并包括您可能遇到的任何错误。(字符串)此处是必要的,其作用是什么??请删除$parsed_results_array=array()代码>因为它在这里什么都不做,我想…正如你所知道的(字符串)被用于类型转换。是的,我知道,但我想问它在简单的回音值中扮演什么角色?@PraveenKumar在这里仔细阅读整个教程:,你会得到你所有的答案的还有其他方法可以得到你的徽章
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>';
}
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) {
echo '<ul>';
echo '<li>' . (string) $item->opponent->name . '</li>';
echo '<li>' . (string) $item->result . '</li>';
echo '<li>' . (string) $item->url . '</li>';
echo '</ul>';
}
}
$parsed_results_array[] = $items;
echo "
<ul>
<li>$items[title]</li>
<li>$items[description]</li>
<li>$items[link]</li>
</ul>
";
<?php
// Some nice php code here ...
?>
<?php foreach( $parsed_results_array as $result ): ?>
<ul>
<?php foreach( $result as $data ): ?>
<li><?php echo $data ?></li>
<?php endforeach ?>
</ul>
<?php endforeach ?>
<?php
// Some other php code there ...
?>