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
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)
}
}
...
}
This is the code
$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?
Thanks
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>';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.