【发布时间】:2017-08-17 08:35:52
【问题描述】:
例如,我有这样的数组:
$someArray = Array (
[stationList] => Array (
[0] => Array (
[stationName] => A.S.Peta Bypass
[stationId] => -1 )
[1] => Array (
[stationName] => Aala
[stationId] => -1 )
)
)
现在你想在 php 的下拉列表中显示数组元素(stationName),我使用了以下代码:
<select id="txtLabourId">
<option selected="selected">Choose one</option>
<?php
foreach($someArray as $name) { ?>
<option value="<?php echo $name['stationName'] ?>"><?php echo $name['stationName'] ?></option>
<?php
} ?>
</select>
但它给出了错误:
Undefined index stationName on line 222
如何解决这个问题?任何帮助表示赞赏。
【问题讨论】:
-
先用stationList检查