doufen3134 2017-09-05 13:22
浏览 13
已采纳

多级数组 - 好像我在圈子里走来走去?

This is an example of the array I am working with

array(7) 
{ 
    ["ClassId"]=> int(26) 
    ["ClassName"]=> string(9) "Candidate" 
    ["Data"]=> array(1) 
    { 
        [0]=> array(8) 
        { 
            ["AppDataId"]=> int(17736) 
            ["FirstName"]=> string(4) "hano" 
            ["LastName"]=> string(11) "steenhuizen" 
            ["CvTxtField"]=> string(4) "coal" 
            ["Telephone"]=> string(6) "2345§" 
            ["Email"]=> string(27) "hano11aaaaa@steenhuizen.com" 
            ["Abstract"]=> string(16) "hano steenhuizen" 
            ["TimeStamp"]=> string(22) "2017-09-05 06:08:41+02" 
        } 
    } 
    ["RowCount"]=> int(1) 
    ["PageNumber"]=> int(1) 
    ["PageSize"]=> int(100) 
    ["QueryTime"]=> string(6) "0.009s" 
}

For the life of me, I just cannot loop this with a basic PHP foreach loop? $objApi contains the array above

echo '<table>';
foreach($objApi as $value)
    {
            echo '<tr><td>' . $value['FirstName'] . '</td></tr>';
    }

echo '</table>

I would love to understand the workings of the array better as for some reason I just cannot get it right.

  • 写回答

3条回答 默认 最新

  • dongwen3093 2017-09-05 13:52
    关注

    The arrays is a tree of values associated to a key, you can define the key and the values as you with, even, you can create a value of a array as another array. The only thing that you have to know is the structure that you array has, at the moment to iterate.

    For you example code, if you want to iterate the data result of your query, this is the way:

    foreach($row['Data'] as $row){
        foreach($row as $user){
            echo '<tr><td>'.$user['FirstName'].'</td></tr>';
        }
    }
    

    I access directly in the array key that has the values of your query

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型