Php 我一直在使用_array()期望参数2是数组,我如何修复它?
警告:in_array()要求参数2为数组,为安全起见,在第229行的文件位置HIDDEN中为null 第223-235行Php 我一直在使用_array()期望参数2是数组,我如何修复它?,php,parameters,Php,Parameters,警告:in_array()要求参数2为数组,为安全起见,在第229行的文件位置HIDDEN中为null 第223-235行 223 if (count($dmos_forum_ids) > 0) { 225 // Loop through the new mgroups and make sure they are added to the existing 226 foreach ($dmos_forum_ids as $id) {
223 if (count($dmos_forum_ids) > 0) {
225 // Loop through the new mgroups and make sure they are added to the existing
226 foreach ($dmos_forum_ids as $id) {
228 // If the current mgroups doesnt have the id...
229 if (in_array($id, $mgroup_others_array)) {
231 // Add it to the array
232 array_push($new_mgroup_others_array, $id);
233 }
234 }
235 }
我添加了行号,以帮助了解行号的位置。
非常感谢您提供的任何帮助您需要确保您的
$mgroup\u others\u array
实际上是一个数组
您可以将更改为以下内容:
if (is_array($mgroup_others_array) && in_array($id, $mgroup_others_array)) {
这将停止您的警告
。不能在数组()中对非一个变量执行调用。也可以执行以下操作:
if (count($dmos_forum_ids) > 0) {
$new_mgroup_others_array = array();
if(!is_array($mgroup_others_array))
$mgroup_others_array = array();
// Loop through the new mgroups and make sure they are added to the existing
foreach ($dmos_forum_ids as $id)
{
if (in_array($id, $mgroup_others_array))
{
array_push($new_mgroup_others_array, $id);
}
}
}
什么不清楚$mgroup\u others\u array
为空在使用它之前定义它,$mgroup\u others\u array=array()代码>