Php MySQLi获取最后一个insert ID并将其传递给true函数

Php MySQLi获取最后一个insert ID并将其传递给true函数,php,mysqli,mysql-insert-id,Php,Mysqli,Mysql Insert Id,在我的示例中,我试图从查询中检索最后一个_insert(ID)true调用函数这里是我调用函数的地方: $lead = $_leadh->addLead($lead_data, $call_data['number'], $user); $LeadID = $lead['id']; function addLead(array $lead_data, $number, $user) { //check if lead with same

在我的示例中,我试图从查询中检索最后一个_insert(ID)true调用函数这里是我调用函数的地方:

$lead = $_leadh->addLead($lead_data, $call_data['number'], $user);
$LeadID = $lead['id'];
function addLead(array  $lead_data, $number, $user) {               

        //check if lead with same number and name exist in db
        if ($checker =  >= 1)
        {
            //return lead id as existed
            $data = $query->fetch_array(MYSQLI_ASSOC);      
            return array('id'=>$data['lead_id'], 'exists'=>true);           
        }
        else
        {
            //insert new lead into db
            if ($query = $this->QueryDB("INSERT", "INTO leads (lead_name)
                                               VALUES ('".$this->EscapeString($lead_data['lead_name'])))
              {
                  //return lead id as new
                  return array('id'=>$this->insert_id, 'exists'=>false);
              }
              else 
              {
                 //output error if insertion fail       
                  return false;
              }
}}
我没有得到任何结果?这是我的addLead函数:

$lead = $_leadh->addLead($lead_data, $call_data['number'], $user);
$LeadID = $lead['id'];
function addLead(array  $lead_data, $number, $user) {               

        //check if lead with same number and name exist in db
        if ($checker =  >= 1)
        {
            //return lead id as existed
            $data = $query->fetch_array(MYSQLI_ASSOC);      
            return array('id'=>$data['lead_id'], 'exists'=>true);           
        }
        else
        {
            //insert new lead into db
            if ($query = $this->QueryDB("INSERT", "INTO leads (lead_name)
                                               VALUES ('".$this->EscapeString($lead_data['lead_name'])))
              {
                  //return lead id as new
                  return array('id'=>$this->insert_id, 'exists'=>false);
              }
              else 
              {
                 //output error if insertion fail       
                  return false;
              }
}}

您正在从
addLead
函数返回数组,但在调用时没有得到任何变量:

$_leadh->addLead($lead_data, $call_data['number'], $user);
$LeadID = $lead['id'];
应如下所示:

$lead = $_leadh->addLead($lead_data, $call_data['number'], $user);
$LeadID = $lead['id'];

是的,很抱歉我错过了代码的这一部分;-)提供
$lead的输出