【问题标题】:PHP: Can't use function return value in context - errorPHP:不能在上下文中使用函数返回值 - 错误
【发布时间】:2023-03-12 22:35:02
【问题描述】:

我不太确定我到底做错了什么,我确实检查了其他问题,我推断出的只是返回(称为“空”的东西)只支持变量,尽管那没有'并没有真正改变任何东西。

当我运行它时,我的代码中出现了一个非常奇怪的错误,并且无法确定它的头或尾。

Fatal error: Can't use function return value in write context in /home/shortcu1/public_html/projects/friendcodes/newUser.php on line 103

这是被调用的主要函数。 (在一个名为 newUser.php 的文件中)

function isBumping($forumid, $username, $premium){
    if($premium == 'true'){
        $file = file_get_contents('plist.txt'); // This is the file I'm testing on
        echo 'Running code as premium<br>';
    } else {
        $file = file_get_contents('list.txt');
    }
    $forumid = $forumid.':'.$username;
    $posts = explode(' ', $file);
    $posts ($info, $bump) = array_filter($posts, function($item) use ($forumid, $posts){
        // This will check for matching forum ID
        if(strpos($item, $forumid) !== true){
            $pos = strpos($item, ':Day-');
            $pos = $pos + 5;
            $day = (int) substr($item, $pos, 1); // Converts the stored date to a numerical value. remember 1 = monday, 7 = sunday
            $today = date('N');
            $bump = false;
            if(($day+3) % 7 > $today){
                // Old enough to re-bump
                return array ($item, $bump);
            } else {
                // Too recent to re-bump
                $bump = true;
                return array ($item, $bump);
            }
        }
    });
    print_r($posts[1]);
    echo '<br>';
    print_r($posts[2]);

}

它正在通过文件 test.php 运行:

include('newUser.php');
isBumping(1, 'Spitfire', 'true')

名为plist.txt的文件如下:

1:Spitfire:Day-4:8JX-UKR8:8JX-UKR8:Spirit:90 1:喷火:Day-4:8JX-UKR8:8JX-UKR8:Spirit:90 1:喷火:Day-4:8JX-UKR8:8JX-UKR8:Spirit:90 1:喷火:Day-4:8JX-UKR8:8JX-UKR8:Spirit:90

【问题讨论】:

    标签: php arrays return


    【解决方案1】:

    array_filter 返回数组中所有非空元素的数组。

    您不能为此使用 $post($a, $b) 尝试更改为变量

    就像简单地$post

    【讨论】:

      【解决方案2】:

      尝试改变

      $posts ($info, $bump) =

      $posts =

      【讨论】:

        猜你喜欢
        • 2010-12-04
        • 2015-04-13
        • 1970-01-01
        • 1970-01-01
        • 2014-09-08
        • 2012-08-21
        • 1970-01-01
        相关资源
        最近更新 更多