$row) { if ($row['pid'] == $parent_id) { $row['level'] = $level; $row[$name] = $this_symbol . $row['name']; $result[] = $row; $pid = $row['id']; unset($data[$key]); $child_data = self::multilevel_linear_sort($data, $symbol, $name, $id_name, $parent_id_name, ($level + 1), $pid); foreach ($child_data as $child_row) { $result[] = $child_row; } } } return $result; } /** * User: 意象信息科技 lr * Desc: 表单多维数据转换 * 例: * 转换前:{"x":0,"a":[1,2,3],"b":[11,22,33],"c":[111,222,3333,444],"d":[1111,2222,3333]} * 转换为:[{"a":1,"b":11,"c":111,"d":1111},{"a":2,"b":22,"c":222,"d":2222},{"a":3,"b":33,"c":3333,"d":3333}] * @param $arr array 表单二维数组 * @param $fill boolean fill为false,返回数据长度取最短,反之取最长,空值自动补充 * @return array */ public static function form_to_linear($arr, $fill = false) { $keys = []; $count = $fill ? 0 : PHP_INT_MAX; foreach ($arr as $k => $v) { if (is_array($v)) { $keys[] = $k; $count = $fill ? max($count, count($v)) : min($count, count($v)); } } if (empty($keys)) { return []; } $data = []; for ($i = 0; $i < $count; $i++) { foreach ($keys as $v) { $data[$i][$v] = isset($arr[$v][$i]) ? $arr[$v][$i] : null; } } return $data; } }