代码:

function analyrn($extra){
    $result=[];

    $arr1 = explode("\r\n",trim($extra));
    foreach($arr1 as $key=>$value){
        $arr2 =explode(':',trim($value));
        $result[$key]['key'] = trim($arr2[0]);
        $result[$key]['value'] =trim($arr2[1]);
    }
    return $result;
}

结果:

array (size=3)
  0 => 
    array (size=2)
      'key' => string '1' (length=1)
      'value' => string '个人' (length=6)
  1 => 
    array (size=2)
      'key' => string '2' (length=1)
      'value' => string '个体户' (length=9)
  2 => 
    array (size=2)
      'key' => string '3' (length=1)
      'value' => string '企业' (length=6)

ps:"\r\n" 要使用双引号

标签: none

添加新评论