Explode comma from array value in codeigniter

I want to blow someone out of an array value. My code.

        $to_ids_string = "";            
        $to_id = $this->input->post('to');            
        for ($r = 0; $r < count($this->input->post('to')); $r++) {
            if ($to_ids_string != "") {
                $to_ids_string = $to_ids_string . "," . $to_id[$r];
            } else {
                $to_ids_string = $to_id[$r];
            }                
        }
       echo $to_ids_string;
            $a = explode(',', $to_ids_string);
            foreach ($a as $item) {
                echo("<li>$item</li>");
                exit;
            }

      

when i echo $ to_ids_string will return 2.3, but when i loop in foreach, it only returns 2, not 3.

+3


source to share


3 answers


Because of your exit, if you use an exit like this, then it's the end of your program and it doesn't repeat anymore.



+2


source


You are forgetting to remove exit;

from the foreach loop. When you write exit

, execution of your code stops. Hence, you are not getting the desired result.



+2


source


Happens because of exit

. Remove exit

from your code.

+1


source







All Articles