这是循环中的数组
(
[Size] => Array
(
[07601-01] => S,
[07601-02] => M,
[07601-03] => L,
[07601-04] => XL,
[07601-05] => XXL,
)
[other] => Array
(
[07601-01] => S,
[07601-02] => M,
[07601-03] => L,
[07601-04] => XL,
[07601-05] => XXL,
)
)
这是我的循环
<?php
foreach($product_atttribute as $attr) {
?>
尺寸
其他 .....等
<?php
}
?>
在上面的循环中,如何将Size
,other
等作为如下标题获取
答案 0 :(得分:3)
foreach($product_attribute as $key => $value) { }
答案 1 :(得分:2)
如果需要,请使用array_keys
检索已传递数组的所有键
答案 2 :(得分:0)
$arr = array(
'Size' => array
(
'07601-01' => 'S',
'07601-02' => 'M',
'07601-03' => 'L',
'07601-04' => 'XL',
'07601-05' => 'XXL',
),
'other' => array
(
'07601-01' => 'S',
'07601-02' => 'M',
'07601-03' => 'L',
'07601-04' => 'XL',
'07601-05' => 'XXL',
)
);
foreach( $arr as $key => $value ) {
echo '<strong>', $key, '</strong><br/>';
$num = 1;
foreach( $value as $size ) {
echo ' ', $num++, '. ', $size, '<br/>';
}
}
输出:
Size
1. S
2. M
3. L
4. XL
5. XXL
other
1. S
2. M
3. L
4. XL
5. XXL