使用数组值创建列表项

时间:2015-06-16 20:23:04

标签: php html arrays jquery-mobile

如何使用此数组列表项创建?每个数组都应该创建一个新的列表项。在底部,我试图用print实现它,但我不知道如何将值设置为html元素。或者我应该创建一个函数而不是打印?

  

数组([0] =>数组([id] => 61 [0] => 61 [autorid] => 13 [1] => 13 [日期] => 2015-06 -11 [2] => 2015-06-11 [经度] => 13.6483 [3] => 13.6483 [纬度] => 53.8249 [4] => 53.8249 [title] => uiuo [5 ] => uiuo [text] => oujo [6] => oujo)[1] =>数组([id] => 62 [0] => 62 [autorid] => 15 [ 1] => 15 [日期] => 2015-06-11 [2] => 2015-06-11 [经度] => 13.6889 [3] => 13.6889 [纬度] => 53.8551 [ 4] => 53.8551 [title] => fghoir [5] => fghoir [text] =>örlhkwrioiw[6] =>örlhkwrioiw)[2] =>数组([id] => 63 [0] => 63 [autorid] => 16 [1] => 16 [日期] => 2015-06-11 [2] => 2015-06-11 [经度] => 13.6888 [3] => 13.6888 [纬度] => 53.8551 [4] => 53.8551 [title] => ghoghnohi [5] => ghoghnohi [text] => hnhj [6] => hnhj) )

print('<li data-corners="false" id="<?php id; ?>" data-shadow="false" data-wrapperels="div" data-theme="b" ><div class="ui-btn-inner ui-li"><div class="ui-btn-text"><a class="ui-link-inherit"><p class="ui-li-aside ui-li-desc"><strong><?php date; ?></strong></p>');
                    print('<p class="ui-li-heading"><?php title; ?><strong></strong></p>');
                    print('<p class="ui-li-desc">class="ui-li-heading"><?php text; ?></p>');
                    print('<p class="ui-li-desc"><?php autor; ?></p>');

                print('</a></li>'); 

2 个答案:

答案 0 :(得分:1)

您将使用foreach,类似这样的

foreach($your_array as $nested_array){
 echo "<li>" . $nested_array['id'] . " - " . $nested_array['date'] . "</li>"
}

并打印print html标记,而不是渲染它们,而是使用echo

是你想要的吗?

答案 1 :(得分:1)

您可以使用foreach。类似的东西:

<ul>

<?php foreach ($nameOfYourArray as $key => $row): ?>

  <li>
    <p><?php echo $row['autorid']; ?></p>
    <p><?php echo $row['date']; ?></p>
    <p><?php echo $row['longitute']; ?></p>
    <!-- and more... -->
  </li>

<?php endforeach; ?>

</ul>