2014-07-09 2 views
-1

У меня есть 3 запросовОбъединение 3 массивов в один

$this->db->select('count(id) as Lead_Current_Month')->from('admin_lead_distribution'); 
$result1=$this->db->get()->result(); 

$this->db->select('count(id) as Lead_Current_Month')->from('level1_lead_distribution'); 
$result2=$this->db->get()->result(); 

$this->db->select('count(id) as Lead_Current_Month')->from('level2_lead_distribution'); 
$result3=$this->db->get()->result(); 

Когда я печатаю это дает

Array 
(
    [0] => stdClass Object 
     (
      [Lead_Current_Month] => 12 
     ) 

) 
Array 
(
    [0] => stdClass Object 
     (
      [Lead_Current_Month] => 38 
     ) 

) 
Array 
(
    [0] => stdClass Object 
     (
      [Lead_Current_Month] => 10 
     ) 

) 

Как совместить 3 массивов в один? Я хочу, чтобы результат:

Array 
(
    [0] => stdClass Object 
     (
      [Lead_Current_Month] => 60 
     ) 

) 

[Lead_Current_Month] => 60 (60 является суммой всех значений 3 массива)

ответ

0

Вы можете просто суммировать значение результатов, и я не» t знать, почему вы хотите хранить информацию в любом массиве/объекте, просто сохраните ее в переменной.

$sum_result = $result1[0]->Lead_Current_Month + $result2[0]->Lead_Current_Month + $result3[0]->Lead_Current_Month; 

echo $sum_result; //will echo 60 
Смежные вопросы