只有变量可以通过引用传递 - php

发布于 2024-12-12 06:33:35 字数 517 浏览 0 评论 0原文

我正在尝试这段代码,但出现此错误:

Only variables can be passed by reference in xxx

脚本

class page {
  function insert($db, $of, $form, &$arr) {

      $i = 0;

      foreach(array_combine($form['value0'], $arr) as $val=>$v){

          $sql->prepare("mysqli query here");
          $sql->bind_param('ssss', $val, $of, $v[$i][0], $v[$i][1]);//error here
          $sql->execute();
          $i++;

      }
      return true;
  }
}

原因是什么,如何解决?谢谢

i am trying this code, but i get this error:

Only variables can be passed by reference in xxx

script

class page {
  function insert($db, $of, $form, &$arr) {

      $i = 0;

      foreach(array_combine($form['value0'], $arr) as $val=>$v){

          $sql->prepare("mysqli query here");
          $sql->bind_param('ssss', $val, $of, $v[$i][0], $v[$i][1]);//error here
          $sql->execute();
          $i++;

      }
      return true;
  }
}

what is the reason, and how can be solved ? thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰魂雪魄 2024-12-19 06:33:35

我假设您正在使用 mysqli::bind_param< /代码>。除第一个参数之外的所有参数均通过引用传递。这意味着它们必须是变量,而不是字符串、数组元素等。我实际上不确定为什么它需要通过引用来执行此操作,但没关系。你可以很容易地修复它:

$v0 = $v[$i][0];
$v1 = $v[$i][1];
$sql->bind_param('ssss', $val, $of, $v0, $v1);

I assume you're using mysqli::bind_param. All arguments except the first are passed by reference. This means they must be variables, and not strings, array elements, etc. I'm actually not sure why it needs to do this by reference, but never mind. You can fix it pretty easily:

$v0 = $v[$i][0];
$v1 = $v[$i][1];
$sql->bind_param('ssss', $val, $of, $v0, $v1);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文