PHP:Can';t在写上下文中使用函数返回值
无法在写上下文中使用函数返回值 所有的搜索结果都说这与空函数有关,但我没有使用它PHP:Can';t在写上下文中使用函数返回值,php,Php,无法在写上下文中使用函数返回值 所有的搜索结果都说这与空函数有关,但我没有使用它 foreach ($permission as explode(',', $permissionString)) { // line 44 if ($this->hasPermission($permission)) $count++; } 在数组中,as左侧的表达式应该是要迭代的数组,右侧的表达式是一个变量,该变量会被数组中每个元素的值覆盖 出现错误的原因是php试图将$permi
foreach ($permission as explode(',', $permissionString)) { // line 44
if ($this->hasPermission($permission))
$count++;
}
在数组中,as
左侧的表达式应该是要迭代的数组,右侧的表达式是一个变量,该变量会被数组中每个元素的值覆盖
出现错误的原因是php试图将$permission
的元素写入explode(',',$permissionString)
,但这会返回一个错误,因为explode(',',$permissionString)
是一个函数调用,而不是一个变量,并且只能写入变量
要解决此问题,请尝试将的顺序颠倒为,如下所示:
foreach (explode(',', $permissionString) as $permission) {
foreach语句中的变量顺序错误。它应该是:foreach(分解(“,”,$permissionString)为$permission)
:foreach(数组\表达式为$value)
。