Q:

Php build array from comma separated array values

I have a array with some array values contains multiple values separated by comma as shown below.  

    $a  =  array(
              '0' => 't1,t2',
              '1' => 't3',
              '2' => 't4,t5'
           );   

I need output in the following format.

   Array
    (
        [0] => t1
        [1] => t2
        [2] => t3
        [3] => t4
        [4] => t5
    )

This is how tried and getting the results. Is there any other alternative way without looping twice.

    $arr_output = array();

    foreach($a as $val)
    {
        $temp = explode(',', $val);
        foreach($temp as $v)
        {
            $arr_output[] = $v;
        }
    }

Thanks.

A:

First convert your old array in to string like,
$old_array =  array
    (
       "t1,t2",
        "t3",
        "t4,t5"
    );
to 

$string = implode(",", $old_array);Nowecho $string; gives a string with coma separator now using this you get desired array
$new_array = explode(",", $string);

If you print this you will get
Array(
[0] => t1
[1] => t2
[2] => t3
[3] => t4
[4] => t5)

