只能通过引用传递变量-php [英] Only variables can be passed by reference - php

查看:72
本文介绍了只能通过引用传递变量-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

推荐答案

我假设您正在使用

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆