本文介紹了多維數組 - 如何從子數組中獲取特定值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有以下數組結構:
<前>大批([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模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!