问题:php下foreach()错误提示Warning: Invalid argument supplied for foreach()
Warning: Invalid argument supplied for foreach() in /www/wwwroot/m2.xxx.com/app/code/Zemez/ThemeOptions/Helper/ColorScheme.php 102
解决办法:
错误提示 Warning:Invalid argument supplied for foreach() 的中文意思是说foreach需要是一个数组而给它的是一个无效的参数.
就是在循环前面加上判断,直接使用is_array判断给的值是不是为数组,代码如下:
if(is_array($items) && !emptyempty($items)){
foreach( )
}
vi app/code/Zemez/ThemeOptions/Helper/ColorScheme.php +102
public function getDefaultStoreValues($store = null)
{
$values = [];
$items = $this->getStoreColorSchemes($store);
if(is_array($items) && !empty($items)){
foreach ($items as $id => $data) {
$values[$id] = $data['params'];
}
}
return $values;
}