类似excel格式数据的数组处理

来源:互联网 发布:java工作流引擎有哪些 编辑:程序博客网 时间:2024/05/22 10:38
#id     name    passwd $str = '1   tom         123 2   jack        4565 absk      435345';$arr = explode("\n", $str);$result = [];$title = ['id', 'name', 'passwd'];foreach ($arr as $item) {    if (empty(trim($item))) {        continue;    }    $temp = preg_split('/[\s]+/', $item);    $temp = array_combine($title, array_filter($temp));    $result[] = $temp;}var_dump($result);
原创粉丝点击