本文介绍了只能通过引用传递变量-php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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;
  }
}

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

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

推荐答案

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

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);

这篇关于只能通过引用传递变量-php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 15:22
查看更多