我试图循环下面的数组。foreach循环后打印阵列不工作
Array
(
[mech_info] => Array
(
[make] => Amaka
[0] => Array
(
[year] => 2001
[model] => Array
(
[0] => Test one
[1] => test fix
[2] => Hamour
[3] => Imagica
)
)
[1] => Array
(
[year] => 2002
[model] => Array
(
[0] => Test Two
)
)
[2] => Array
(
[year] => 2014
[model] => Array
(
[0] => Test three
)
)
[3] => Array
(
[year] => 2015
[model] => Array
(
[0] => test four
)
)
)
)
Array
(
[mech_info] => Array
(
[make] => PRI
[0] => Array
(
[year] => 2005
[model] => Array
(
[0] => PRIMODE
[1] => Temp Pri
[2] => primode
[3] => yyy
)
)
)
)
我想用foreach循环来做。我已经通过下面的代码尝试,但它没有显示出除了
`print_r($_POST['mech_show']);`.
$all_make_model= $_POST['mech_show'];
$all_make_model_data = $all_make_model['mech_info'];
foreach ($all_make_model_data as $key => $mec_value) {
echo "string";
echo $meta_value['make'];
}
echo "<pre>";
print_r($_POST['mech_show']);
exit();
也无法foreach
和数据去下在循环不显示任何信息。
给我的错误
注意:未定义指数:mech_info
Warning: Invalid argument supplied for foreach() in
我也TRIE这种方式,但
$all_make_model= $_POST['mech_show'];
$all_make_model_data = $_POST['mech_info'];
foreach ($all_make_model as $key => $mec_value) {
echo "<pre>";
print_r($mec_value['make']);
echo "</pre>";
}
echo "<pre>";
print_r($all_make_model['mech_info']);
但它showing Warning: Illegal string offset 'mech_info' in ..
我不知道我的代码是否错误,或者我错过了任何人可以帮助我。
谢谢
错字'回声$ meta_value [ '让'];'应该是'回声$ mec_value [ '让']' – jitendrapurohit
'的foreach($ all_make_model_data as $ key => $ mec_value){ echo“string”; echo $ mec_value ['make']; }' –
你可以var_dump你的mech_show?我试图创建你的对象,并且我得到了一个空数组 – GiuServ