将3个阵列合并为一个

时间:2014-07-09 13:33:06

标签: mysql sql arrays codeigniter activerecord

我有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个数组值的总和)

1 个答案:

答案 0 :(得分:0)

您可以总结结果的值,我不知道您为什么要将信息存储在任何数组/对象中,只需将其存储在变量中。

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

echo $sum_result; //will echo 60