循环遍历subArray为$ key => PHP中的$ value [英] loop through subArray as $key => $value in PHP
本文介绍了循环遍历subArray为$ key => PHP中的$ value的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出数据结构:
array(2) {
[0] array(7) {
["model_id"] 218
["total"] 10
["brand"] "This Brand"
["model_name"] "This Name"
["picture"] "this pic.jpg"
["color"] "Black"
["sizes"] array(3) {
["4"] "10 %"
["5"] "80 %"
["6"] "10 %"
}
}
[1] array(7) {
["model_id"] 219
["total"] 10
["brand"] "This Brand"
["model_name"] "ThatName"
["picture"] "that pic.jpg"
["color"] "Black"
["sizes"] array(3) {
["4"] "20 %"
["5"] "50 %"
["6"] "30 %"
}
}
}
如何以 $ key =>循环尺寸 $ value
?
How can you loop into sizes as $key => $value
?
到目前为止,我尝试的功能都没有,比如嵌套循环。
What I tried didn't work so far, like nested loops.
foreach($array as $i){
foreach($i as $z){
foreach($z as $key => $value){
print_r($key);
}
}
}
}
导致错误: 为foreach()提供的参数无效
results in error: Invalid argument supplied for foreach()
推荐答案
foreach($array as $i){
foreach($i['sizes'] as $key => $value){
echo $key.'->'.$value;
}
}
这篇关于循环遍历subArray为$ key => PHP中的$ value的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文