我正在和提供的foreach错误无效参数()中的代码波纹管。任何人都可以告诉我我在这里做错了什么?我正在尝试访问这里的子数组值[0]和[1]。只是要提到,我不知道现在许多值将在子数组中。解决不了这个()的foreach为无效的论点提供
我已经把上面的代码出错行的
echo "<pre>";
print_r($mySessData);
echo "</pre>";
Array
(
[addtypeid] =>
[isnew] =>
[orderby] =>
[geographicareaid] =>
[catid] => 1
[catid2] =>
[manufacturerid] =>
[modelid] =>
[yearofmanufacturing_from] =>
[yearofmanufacturing_to] =>
[hoursused_from] =>
[hoursused_to] =>
[horsepowers_from] =>
[horsepowers_to] =>
[price_from] =>
[price_to] =>
[colorid] =>
[isdamaged] =>
[categoriesfilters] =>
Array
(
[0] => 67
[1] => 158
)
)
$sessData = array();
$myresult = array();
$val = array();
if (!empty($mySessData)){
foreach ($mySessData as $sessData) {
// the line bellow is the offending line, where the error is thrown
foreach ($sessData as $val) {
$myresult[$val]= $val;
foreach($filters as $f) {
if ($f['filterid'] == $myresult[$val]) {
$strWhere2 .= $myresult[$val] .",";
} // end if
} // end of third foreach
} // end of second foreach
} // end of first foreach
} // end if
迭代条件与'如果(is_array($ sessData)){的foreach ...' – pce
你的代码的伎俩。让它成为答案,所以我可以接受它。谢谢。 – user2417624
代码包含一些非意义上,我强烈建议您在foreach文档上阅读例如:http://php.net/manual/fr/control-structures.foreach.php – Asenar