// 无限极分类 转换成tree结构
function getTree($list) {
$tree = [];
$list = array_column($list, null, 'id');
foreach($list as $val){
if(isset($list[$val['pid']])) {
$list[$val['pid']]['children'][] = &$list[$val['id']];
} else {
$tree[] = &$list[$val['id']];
}
}
return $tree;
}
$a = [
['id' => 1, 'pid' => 0, 'name' => '安徽省', '666' => '111'],
['id' => 2, 'pid' => 1, 'name' => '合肥市', '666' => '111'],
['id' => 3, 'pid' => 2, 'name' => '蜀山区', '666' => '111'],
['id' => 4, 'pid' => 2, 'name' => '经开区', '666' => '111'],
['id' => 5, 'pid' => 0, 'name' => '河南省', '666' => '111'],
['id' => 6, 'pid' => 5, 'name' => '开封市', '666' => '111'],
['id' => 7, 'pid' => 1, 'name' => '六安市', '666' => '111'],
['id' => 8, 'pid' => 7, 'name' => '裕安区', '666' => '111'],
['id' => 9, 'pid' => 4, 'name' => '经开区中环城', '666' => '111'],
['id' => 10, 'pid' => 9, 'name' => '经开区中环城一楼', '666' => '111'],
['id' => 11, 'pid' => 9, 'name' => '经开区中环城二楼', '666' => '111'],
];
$a = getTree($a);
myPrint($a);
// 身份证 手机号 正则判断
if(!preg_match("/^1[3456789]\d{9}$/", $data)){
$result['msg'] = '手机号码不正确';
$this->ajaxReturn($result);
}
if(!preg_match("/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/", $data)){
$result['msg'] = '身份证号码不正确';
$this->ajaxReturn($result);
}
// 用习惯的自定义打印方法
function myPrint($data, $var_dump = 0, $is_die = 1)
{
echo '<pre>';
if ($var_dump) {
var_dump($data);
} else {
print_r($data);
}
if ($is_die) {
die;
}
}
|