Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 值为空时出现致命错误_Php_Wordpress - Fatal编程技术网

Php 值为空时出现致命错误

Php 值为空时出现致命错误,php,wordpress,Php,Wordpress,我有一个致命错误,当我认为我有一个数组时,我声称我有一个字符串: 致命错误:[]第566行的/Applications/MAMP/htdocs/tankards\u wordpress/wp content/themes/tankardsleague/functions.php中的字符串不支持运算符 以及以下警告: 警告:in_array()希望参数2是数组,第579行的/Applications/MAMP/htdocs/tankards\u wordpress/wp content/theme

我有一个致命错误,当我认为我有一个数组时,我声称我有一个字符串:

致命错误:[]第566行的/Applications/MAMP/htdocs/tankards\u wordpress/wp content/themes/tankardsleague/functions.php中的字符串不支持运算符

以及以下警告:
警告:in_array()希望参数2是数组,第579行的/Applications/MAMP/htdocs/tankards\u wordpress/wp content/themes/tankardsleague/functions.php中给出的字符串

我猜我可能有语法问题?我以为我已经初始化了变量,但也许我错过了一个?我希望能有一些更有经验的眼睛看看

function forum_subscribe_member_player()
{
    global $user_ID;
    $players= get_users();

    foreach($players as $player)
    {
        $user_info = get_userdata($player->ID);
        $playeremail = $user_info->user_email;

        if(!empty($playeremail) && user_can( $player-> ID, 'contributor'))
        {                   
            $list = get_option('mf_forum_subscribers_1', array());


            if( is_player_subscribed($player->ID)) //remove player if already exists (user clicked unsubscribe)
            {
                $key = array_search($playeremail, $list);
                unset($list[$key]);
            }
            else
                $list[] = $playeremail;
            update_option('mf_forum_subscribers_1', $list);
        }
    }       
}

function is_player_subscribed($user_ID)
{
    if($user_ID)
      {
        $useremail = get_userdata($user_ID, 'user_email');

        $list = get_option("mf_forum_subscribers_1", array());
        if(!empty($list) && in_array($useremail, $list))
        {
          return true;
        }
        return false;
      }

}

function call_forum_subscribe_member_player()
{
    forum_subscribe_member_player();
} 

第566行是
$list[]=$playeremail第579行是
如果(!empty($list)和&in_array($useremail,$list))

那么,您可以将
$list
类型强制转换为数组,以确保它始终是数组,即使初始值为null/empty/etc(基本上是除数组之外的任何类型):


您可以将
$list
类型强制转换为一个数组,以确保它始终是一个数组:
$list=(array)get_选项('mf_论坛_订阅者_1',array())第566行是
$list[]=$playeremail第579行是'if(!empty($list)&&in_array($useremail,$list))`感谢@Twisted1919处理了警告,但仍然得到了
$list[]=$playeramail的致命错误$playeremail确实是一个字符串,但我正在尝试添加一个字符串数组。@Twisted1919获得了它,谢谢(我没有对两个实例都使用您的建议),如果您想将它放在正确的答案形式中。
$list = (array)get_option('mf_forum_subscribers_1', array());