【问题标题】:Multi dimension array formatting多维数组格式化
【发布时间】:2015-12-13 19:39:47
【问题描述】:

我想用 type 的键来回显数组值,这是我的代码,

foreach ($sam as $key => $sa) {
    foreach ($sa as $s) {
        echo $s['type'];
    }
}

这是数组$sam的内容

array (size=1)
  0 => 
    array (size=5)
      'type' => string 'days' (length=4)
      'bookable' => string 'no' (length=2)
      'priority' => int 10
      'from' => string '1' (length=1)
      'to' => string '1' (length=1)

我的 foreach 代码结果系列 警告:非法字符串偏移 'type' 我不知道为什么?你能帮我回声type吗谢谢。

【问题讨论】:

    标签: php multidimensional-array


    【解决方案1】:

    你只需要一个foreach:

    foreach ($sam as $s) {
        echo $s['type'];
    }
    

    【讨论】:

      猜你喜欢
      • 2021-05-13
      • 2021-10-28
      • 2021-12-02
      • 2014-09-05
      • 2021-05-02
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多