$v){ $item = []; $item['value'] = $v; $item['label'] = $v; $first = []; foreach ($arr[$k] as $k1 => $v1){ $second = []; if(array_key_exists($k1,$arr)){ foreach ($arr[$k1] as $k2 => $v2){ $item2 = [ 'value' => $v2, 'label' => $v2 ]; array_push($second,$item2); } $item1 = [ 'value' => $v1, 'label' => $v1, 'children' => $second ]; }else{ $item1 = [ 'value' => $v1, 'label' => $v1 ]; } array_push($first,$item1); } $item['children'] = $first; array_push($res,$item); } echo "
";
echo json_encode($res,JSON_UNESCAPED_UNICODE);