doufu1950 2017-09-24 11:53
浏览 22
已采纳

PHP数组到表

I am using foreach to get the values of the array in a table but am having difficulty getting the values to show in one line. Please Help.

I've currently got this piece of code but using it only shows the values of [value] underneath eachother:

<?php
foreach($row as $level => $priv){
foreach($priv as $command => $list){
foreach($list as $trigger => $value){       
echo  $value;}}}?>

The Array

[rows] => SimpleXMLElement Object
            (
                [row] => Array
                    (
                        [0] => SimpleXMLElement Object
                            (
                                [rownum] => 1
                                [values] => SimpleXMLElement Object
                                    (
                                        [value] => Array
                                            (
                                                [0] => 12345567
                                                [1] => BC INC
                                                [2] => 9756208
                                                [3] => OTC
                                                [4] => Marketers
                                                [5] => OTC Pink
                                                [6] => BDCG
                                                [7] => 2390
                                                [8] => Misc Products
                                            )

                                    )

                            )

                        [1] => SimpleXMLElement Object
                            (
                                [rownum] => 2
                                [values] => SimpleXMLElement Object
                                    (
                                        [value] => Array
                                            (
                                                [0] => 12345678
                                                [1] => MEDIA, INC.
                                                [2] => 123456
                                                [3] => OTC
                                                [4] => OT
                                                [5] => OTC
                                                [6] => BDDE
                                                [7] => 876856
                                                [8] => Biz Services
                                            )

                                    )

                            )
  • 写回答

1条回答 默认 最新

  • duanbi3151 2017-09-24 15:34
    关注

    Assuming $row is your given SimpleXMLElement the code would work like this:

    foreach($row->rows->row as $entry) {
        printr $entry->values->value;
    }
    

    As you see the print gives out the array where the values are. If you want to have it on some kind of one line you could then go around it with another foreach:

    foreach($row->rows->row as $entry) {
        foreach ($entry->values->value as $value) {
           echo $value." "; // echo the current value
        }
        echo "<br>"; // add a br for the output of the next entry
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度