我有以下数组结构:
Array ( [0] => Array ( [product_option_id] => 236 [option_id] => 14 [name] => Masura S [type] => select [option_value] => Array ( [0] => Array ( [product_option_value_id] => 33 [option_value_id] => 53 [name] => Alb [price] => [price_prefix] => + ) [1] => Array ( [product_option_value_id] => 35 [option_value_id] => 55 [name] => Rosu [price] => [price_prefix] => + ) ) [required] => 0 ) [1] => Array ( [product_option_id] => 237 [option_id] => 15 [name] => Masura M [type] => select [option_value] => Array ( [0] => Array ( [product_option_value_id] => 34 [option_value_id] => 58 [name] => Rosu [price] => [price_prefix] => + ) ) [required] => 0 ) )
我发现自己在尝试显示此数组中的所有[name]值时迷失了方向.
我想要做的是使用下拉选择填充表单,基于第一级[名称](如[name] => Masura S),然后第二个下拉选择第二级[名称](如[名称] ] => Alb).
如果您有任何指示,我将不胜感激……
你可以用这种方式填充第一个选择:
原文链接:https://www.f2er.com/php/134940.html<select> <?PHP $c=count($array); for ( $i=0; $i < $c; $i++) { ?> <option><?PHP echo $array[$i]['name'];?></option> <?PHP } ?> </select>
第二选:
<select> <?PHP for ( $i=0; $i < $c; $i++) { $c2=count($array[$i]); for ($j=0;$j<$c2;$j++){ ?> <option><?PHP echo $array[$i][$j]['name'];?></option> <?PHP }} ?> </select>