0

我正在寻找一种在 PHP 中回显我的价值观的方法。

我有这个数组:

$arr = array(
    'Golfs' => array('table' => 'Golfs', 'IntExt' => 'extern', 'SummerWinter' => 'summer'),
    'Beaches' => array('table' => 'Beaches', 'IntExt' => 'extern', 'SummerWinter' => 'summer'),
    'MunicipalRegionalParks' => array('table' => 'MunicipalRegionalParks', 'IntExt' => 'extern', 'SummerWinter' => 'summer'),
    'ThemeParks' => array('table' => 'ThemeParks', 'IntExt' => 'extern', 'SummerWinter' => 'summer'),
    'Caves' => array('table' => 'Caves', 'IntExt' => 'intern extern', 'SummerWinter' => 'summer')
);

我想为每一个回应:

  • 表名
  • IntExt 值
  • 夏季冬季价值

我试过了:

foreach($arr['table'] as $result) {
    echo $result['IntExt'], '<br>';
}

但是:警告:为 foreach() 提供的参数无效

谢谢。

4

3 回答 3

1
foreach($arr as $key => $value) {
    echo $value['IntExt'].'<br/>';
}
于 2013-10-11T17:58:57.207 回答
1
foreach($arr as $set){
  foreach($set as $data){
    echo $data . "<br/>" ;
  }

  echo "<br/>" ;
}
于 2013-10-11T18:01:02.547 回答
0

尝试这个 :

foreach($arr as $key => $result) {
    echo "<strong>" . $key . "</strong><br>";
    echo "table name : " . $result['table'] . "<br>";
    echo " IntExt : " . $result['IntExt'] . "<br>";
    echo "SummerWinter : " . $result['SummerWinter'] . "<br>";
    echo "--------------------------------------------------<br><br>";
}

输出

Golfs
table name : Golfs
IntExt : extern
SummerWinter : summer
--------------------------------------------------

Beaches
table name : Beaches
IntExt : extern
SummerWinter : summer
--------------------------------------------------

MunicipalRegionalParks
table name : MunicipalRegionalParks
IntExt : extern
SummerWinter : summer
--------------------------------------------------

ThemeParks
table name : ThemeParks
IntExt : extern
SummerWinter : summer
--------------------------------------------------

Caves
table name : Caves
IntExt : intern extern
SummerWinter : summer
--------------------------------------------------
于 2013-10-11T17:59:27.440 回答