多维数组在HTML和PHP中不能这样工作。基于评论
<option value="bus_info[{$k->bus_id}][{$k->route_from}][{$k->route_to}]">{$k->route_from} To {$k->route_to},{$k->bus_time}</option>
编辑:你应该在你的形式使用该
对不起,这不会在所有的工作。我假设你想让用户选择某种路线,并基于你想传递一个特定的值。该方式<select>
的工作原理是:
在HTML使用:
<select name="test">
<option value="1">First option</option>
<option value="2">Second option</option>
</select>
现在,在PHP中可以访问已提交这样的值:
$_REQUEST['test'] //this value will be 1 if the user
//selected the first option, or 2 if
//he selected the second
您可以使用在输入字段的名称阵列,所以这将有可能在HTML中做这样的事情:
<select name="test[1]">
<option value="1">First option</option>
<option value="2">Second option</option>
</select>
<select name="test[2]">
<option value="1">First option</option>
<option value="2">Second option</option>
</select>
请注意,我在name
属性上使用了数组表示法,而不是数值。现在你可以在PHP中做到这一点:
$_REQUEST['test'][1] //this value will be 1 if the user
//selected the first option, or 2 if
//he selected the second in the first
//drop down
$_REQUEST['test'][2] //this value will be 1 if the user
//selected the first option, or 2 if
//he selected the second in the second
//drop down
你做那么,用在value
属性阵列将无法工作。你可以做这样的事情:
<select name="bus_info">
<option value="{$k->bus_id},{$k->route_from},{$k->route_to}">{$k->route_from} To {$k->route_to},{$k->bus_time}</option>
</select>
然后在PHP:
$values = explode($_REQUEST['bus_info']);
//now $values is an array with 3 elements, the ID, the route_from and route_to
值经由传递' $ _REQUEST ['bid']'只是一个字符串,并不像你期望的那样是一个数组(它是一个字符数组,这就是为什么'bus_information [0] [0]'返回'b'的原因,但是在这一点上不相关)。您需要解析数据以提取逗号分隔值。 – mdm 2012-01-12 12:42:41
因为你所拥有的不是一个数组,它是一个*字符串*,模糊地看起来像一个数组。 – deceze 2012-01-12 12:43:40