explode two-item-list in array as key=>value

后端 未结 3 955
不知归路
不知归路 2021-02-06 05:12

I\'d like to explode a multi-line-string like this

color:red
material:metal

to an array like this

$array[\'color\']=red
$array[         


        
3条回答
  •  春和景丽
    2021-02-06 05:46

    Try this

    $value = '1|a,2|b,3|c,4|d';
    $temp = explode (',',$value);
    foreach ($temp as $pair) 
    {
        list ($k,$v) = explode ('|',$pair);
        $pairs[$k] = $v;
    }
    
    print_r($pairs);
    

提交回复
热议问题