Q:

array isn't combining with loop in php

i've a array problem couldn't just solve it:
here's the code that is already in a foreach loop. i'm getting the $row->class_id value from this loop. it works fine and get me the total students row within an array and i preserved it in $total_student_of_this_class variable. i used another foreach loop for storing the result of first loop and then second loop and so on. but this loop gives only first loop result.
i need to combine the all array of total iteration of the loop.
    $total_student_of_this_class =     
    $this->db->select('student_id')->where('class_id',  
    $row->class_id)->get('student')->result_array();

    echo count($total_student_of_this_class);
    // prints 2 in the first row of the output table and 5 in the second 
    row for me.

    $total_student = array();
    foreach ($total_student_of_this_class as $tt)
    {
    $total_student[] = $tt;

    }

     echo '<pre>';
     print_r($total_student_of_this_class);
     echo '</pre>'

     echo count($total_student);
     // prints only 2 outside the loop (not 7)

pls someone help me.

A:

The problem here is seems to be with $total_student = array();: initializing array inside an other loop it always starts it from zero values array, so you get only results from one iteration inside it and doesn't collect all datas.
You can also look at array_merge php function.

