Multidimensional array - how to get specific values from sub-array(多维数组 - 如何从子数组中获取特定值)
问题描述
我有以下数组结构:
<前>大批([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>
这篇关于多维数组 - 如何从子数组中获取特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:多维数组 - 如何从子数组中获取特定值
基础教程推荐
- 使用 PDO 转义列名 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01