多维数组拼接成字符串

多维数组拼接成字符串
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  
/**
* @FuncName:arrayToString
* @Description 数组拼接成字符串
* @User ZHaoGuiBin
* @Date 2020-08-14 9:17
* @param $data
* @param string $keys
* @param string $key_1 //多维数组主key
* @param string $string
* @return string
*/
private static function arrayToString($data, $keys = '', $string = '', $key_1 = '')
{
$temp = 0;
foreach ($data as $key => $value) {
if (is_array($value)) {
if (!is_numeric($key)) {
$key_1 = $key;
$string .= $key_1 . '=';
}
$string .= self::arrayToString($value, $key, '', $key_1);
} else {
if ($keys) {
if (is_numeric($key)) {
if ($temp == 0) {
$string .= $keys . '=' . $value;
$temp++;
} else {
$string .= '&' . $value . '&';
}
} else {
if ($temp == 0) {
if (!is_numeric($keys)) {
$string .= $keys . '=' . $key . '=' . $value . '&';
$temp++;
} else {
$string .= $key . '=' . $value . '&';
$temp++;
}

} else {
$string .= $key . '=' . $value . '&';
}
}
} else {
$string .= $key . '=' . $value . '&';
}
}
}
return $string;
}