如何在php中从多维数组中增加下拉列表 [英] How to inflate the dropdown from the multidimentional array in php
问题描述
我正在尝试遍历数组以增加下拉列表。但是我不能这样做。我为此尝试了许多方法。但是没有任何东西适合我。我在下面尝试的方法之一
I am trying to loop through an array for inflate the dropdown. But I am not able to do so. I have tried many methods for this. But Nothing works for me. One of the method I try below
这里是我要在下拉菜单中填充的数组。我要膨胀的单个数组中有22个数组。
Here is the array which I am trying to inflate in dropdown. There are 22 array in this single array which I am trying to inflate.
array(22) {
[0] => array(4) {
[0] => string(26) "Black Angled Buckle Jacket"
[1] => string(6) "036890"
[2] => int(48503)
[3] => array(4) {
[0] => string(83) "http://thebestofcards.com/wp-content/uploads/2016/09/product-man-6a-uai-480x640.jpg"
[1] => int(480)
[2] => int(640)
[3] => bool(false)
}
}
...
}
这是代码
$result = count($data);
var_dump($data);
for ($row = 0; $row < $result; $row++) {
//echo "<p><b>Row number $row</b></p>";
echo '<select name="productddl">';
//echo "<ul>";
for ($col = 0; $col < 3; $col++) {
echo '<option value="'.$data[$row][$col][0].'">'.$data[$row][$col][1].'</option>'
//echo "<li>".$data[$row][$col]."</li>";
}
echo '</select>';;
//echo "</ul>";
}
我只想将数组中的产品名称提取到下拉列表中。有人可以帮忙吗?
I just want to fetch the product name in the array to the dropdown. Can anybody help?
谢谢
推荐答案
那不是那么困难,数组不是太嵌套,它只是产品列表,唯一的问题是,您不用数字就使用assoc和更有意义的键,而有了数字。
that's not so difficult, array isn't too nested, it is just a list of products, the only issue is that instead of using assoc and more meaningful keys, you have numbers.
echo '<select name="productddl">';
foreach ($data as $row) {
echo '<option value="', $row[1], '">', $row[0] , '</option>';
}
echo '</select>';
这篇关于如何在php中从多维数组中增加下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!