我有以下数组结构:
<前>大批([0] => 数组([product_option_id] => 236[option_id] => 14[名称] => Masura S[类型] => 选择[option_value] => 数组([0] => 数组([product_option_value_id] => 33[option_value_id] => 53[名称] => 阿尔伯[价格] =>[价格前缀] => +)[1] => 数组([product_option_value_id] => 35[option_value_id] => 55[名称] => 罗苏[价格] =>[价格前缀] => +))[必需] => 0)[1] => 数组([product_option_id] => 237[option_id] => 15[名称] => Masura M[类型] => 选择[option_value] => 数组([0] => 数组([product_option_value_id] => 34[option_value_id] => 58[名称] => 罗苏[价格] =>[价格前缀] => +))[必需] => 0))我发现自己在试图显示此数组中的所有 [name] 值时迷失了方向.
我想要做的是根据第一级[name](如[name] => Masura S)用下拉选择填充表单然后第二个下拉选择带有第二级 [name](如 [name] => Alb).
如果您有任何指点,我将不胜感激...
您可以通过以下方式填充第一个选择:
二选:
I have the following array structure:
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
)
)
I find myself lost in trying to display all the [name] values from this array.
What I am trying to do is to populate a form with dropdown selects based on the first level [name] (like [name] => Masura S) and then a second dropdown select with the second level [name] (like [name] => Alb).
I would appreciate it if you have any pointers...
You can populate the first select this way:
<select>
<?php $c=count($array);
for ( $i=0; $i < $c; $i++)
{ ?>
<option><?php echo $array[$i]['name'];?></option>
<?php } ?>
</select>
2nd 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>
这篇关于多维数组 - 如何从子数组中获取特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 SELECT(MYSQL/PHP) 中加入 2 个表Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 个表)
如何使<option selected=“selected">由How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 设置?)
使用 PHP 中的数组自动填充选择框Auto populate a select box using an array in PHP(使用 PHP 中的数组自动填充选择框)
PHP SQL SELECT where like search item with multiple wordsPHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(),名称 ASCMySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名称 ASC)