splat运算符,如何在PHP 5.4中避免它?

时间:2018-09-10 16:48:33

标签: php splat

我有一些如下代码:

if ($arrayCount >= 1)
{
    $s = "";
    for ($x = 0; $x < $arrayCount; $x ++)
    {
        $s = $s + 's';
    }

    $stmt->bind_param($s, ...$arrayThings);
}

如何不使用splat运算符替换以下行:

$stmt->bind_param($s, ...$arrayThings);

$ arrayThings是一个数组。 $ arrayCount是数组的计数,即记录总数。

我在“ $ stmt-> bind_param($ s,... $ params);”行中遇到“解析错误:语法错误,意外的'。'”。据我所读,这是因为我在主机中使用PHP 5.4。在我的本地计算机上,PHP 5.6中的相同代码可以正常工作。

我已经在这里检查了

https://stackoverflow.com/questions/44684728/php-5-4-17-alternative-for-the-operator

但是我仍然无法弄清楚如何对我的案件适用。 你能给我发一些例子吗?

我的尝试:

call_user_func_array(array($stmt,'bind_param'),explode($arrayThings));
call_user_func_array(array($stmt,'bind_param'),$s,$arrayThings);
call_user_func_array(array($stmt,'bind_param'),$arrayThings);

任何帮助都会得到好评,在此先感谢您, 费利佩

0 个答案:

没有答案