explode comma from an array value in codeigniter

Viewed 290

I want to explode coma from an array value. My code is.

        $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 it will return 2,3 but when i loop in foreach it only return 2 not show 3.

3 Answers
Related