phparraysexplodedelimited

Split the delimited values in a flat array and populate arrays with column values


I had a array of list like this :

A = (a.11, b.12, c.dd)

I want to store the above array values in two different arrays like

B = (a, b, c)
C = (11,12,dd)

Solution

  • Hope this will help you:

    $a = array("a.11,b.12,c.dd");
    $b = array();
    $d = array();
    foreach ($a as $val)
    {
        $c =explode(',', $val);
        foreach ($c as $v)
        {
            $e =explode('.', $v);
            array_push($b,$e[0]);
            array_push($d,$e[1]);
        }
    }
    
    print_r($b);
    print_r($d);
    

    Working demo