dongrang2140 2014-02-12 19:21
浏览 26

输出数组的值

I'm trying to take the values of an array and display it as a list. I've used a foreach to do this before but for some reason I can't figure out why it's not working this time around. In the code below, $output is the contents of an entire page generated through AJAX and is later echo'd out on the bottom of the script. Everything seems to be working except this one small section. I managed to get this exact same information to display on a separate static page (without the $output) so I'm not sure why it's not working here.

       if(!empty($record['utilities'])) {
            $output .= "<ul>"; 
                foreach ($record['utilities'] as $eachUtility):
             // $output .= "<li>" echo $eachUtility; "</li>";
                $output .= "<li>" . $eachUtility . "</li>";
                endforeach;
            $output .= "</ul>";

         // $output .= $record['utilities']; This works
        }

Here's a working example of the same code that was hard coded on a separate page:

        <?php if(!empty($record['utilities'])) { ?>
        <ul>
        <?php foreach ($record['utilities'] as $eachUtility): ?>
        <?php echo ('<li>' . $eachUtility . '</li>'); ?>
        <?php endforeach ?>
        </ul>
        <?php } ?>
  • 写回答

1条回答 默认 最新

  • dongyou6847 2014-02-12 19:25
    关注

    Try this:

    $output = "<ul>"; 
    foreach ($record['utilities'] as $eachUtility) {
        $output .= "<li>" . $eachUtility . "</li>";
    }
    $output .= "</ul>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来