【发布时间】:2015-11-11 12:18:49
【问题描述】:
我在 php 脚本中设置了以下数组,我正试图按照下面的代码将其输出。我试过循环,但我不知道如何让它显示子数组。我希望有人可以帮助我。
PHP 数组
$fruits = array();
$fruits[] = array('type' => 'Banana', 'code' => 'ban00');
$fruits[] = array('type' => 'Grape', 'code' => 'grp01');
$fruits[] = array('type' => 'Apple', 'code' => 'apl00',
array('subtype' => 'Green', 'code' => 'apl00gr'),
array('subtype' => 'Red', 'code' => 'apl00r')
);
$fruits[] = array('type' => 'Lemon', 'code' => 'lem00');
期望的输出
<ul>
<li><input type="checkbox" name="fruit" value="Banana"> Banana</li>
<li><input type="checkbox" name="fruit" value="Grape"> Grape</li>
<li>Apple
<ul>
<li><input type="checkbox" name="fruit" value="Green"> Green</li>
<li><input type="checkbox" name="fruit" value="Red"> Red</li>
</ul>
</li>
<li><input type="checkbox" name="fruit" value="Lemon"> Lemon</li>
</ul>
【问题讨论】:
-
您有尝试过的代码示例吗?你甚至可以输出一个单维数组吗?如果您这样做,我们可以更轻松地继续前进。
标签: php html multidimensional-array