我是php的新手,我正在运行问题,我必须在php函数中传递一个数组作为参数,当我这样做时我得到数组到字符串错误。你们可以帮助我吗?< / p>
这是辅助函数:
private function userinfo($info,$args=''){
try{
if($args===''){
return $this->user->authenticate($this->username,$this->pswd,$info);
}
return $this->user->authenticate($this->username,$this->pswd,$info,$args);
}catch(exception $e){
}
}
这是名为:
的添加功能 public function addUser($id,$email,$name){
$this->userinfo('add',array(0=>$id,1=>$email,2=>$name));
}
答案 0 :(得分:0)
试试这个:
private function userinfo($info,$args = array()){
try{
if(empty($args)){
return $this->user->authenticate($this->username,$this->pswd,$info);
}
return $this->user->authenticate($this->username,$this->pswd,$info,$args);
}catch(exception $e){
}
}
public function addUser($id,$email,$name){
$this->userinfo('add',array(0=>$id,1=>$email,2=>$name));
}
答案 1 :(得分:0)
您正在函数参数中定义一个字符串,但是将数组传递给函数请修改您的代码,如:
private function userinfo($info, $args = []) {
try {
if (!is_array($args) {
return $this->user->authenticate($this->username, $this->pswd, $info);
}
return $this->user->authenticate($this->username, $this->pswd,$info, $args);
} catch(exception $e) {
}
}