如何访问二维数组中的列值? [重复]

问题描述 投票:0回答:1

我想用

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 arrays multidimensional-array
1个回答
2
投票

每个人只需要一个:

foreach ($sam as $s) {
    echo $s['type'];
}
© www.soinside.com 2019 - 2024. All rights reserved.