<table class="text">
<tr class="li1"><td class="ln"><pre class="de1">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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 array( "a" => "orange", "b" => "banana", "c" => "apple" ), "numbers" => array( 1, 2, 3, 4, 5, 6 ), "holes" => array( "first", 5 => "second", "third" ) ); var_dump($fruits); array (size=3) 'fruits' => array (size=3) //关系数组 'a' => string 'orange' (length=6) 'b' => string 'banana' (length=6) 'c' => string 'apple' (length=5) 'numbers' => array (size=6) //索引数组 0 => int 1 1 => int 2 2 => int 3 3 => int 4 4 => int 5 5 => int 6 'holes' => array (size=3) 0 => string 'first' (length=5) 5 => string 'second' (length=6) 6 => string 'third' (length=5) 数组分没有键名的索引数组和有键名关系数组,还有混合数组 //返回字符串键名全为小写或大写的数组 $input_array = array( "FirSt" => 1, "SecOnd" => 4 ); var_dump ( array_change_key_case ( $input_array, CASE_UPPER )); array (size=2) 'FIRST' => int 1 'SECOND' => int 4 键名全部大写 var_dump ( array_change_key_case ( $input_array )); //默认是CASE_LOWER(小写) array (size=2) 'first' => int 1 'second' => int 4 键名全部小写 //将一个数组分割成多个数组,按数组元素分割 $input_array = array( 'a', 'b', 'c', 'd', 'e' ); var_dump ( array_chunk ( $input_array, 2 )); array (size=3) 0 => array (size=2) 0 => string 'a' (length=1) 1 => string 'b' (length=1) 1 => array (size=2) 0 => string 'c' (length=1) 1 => string 'd' (length=1) 2 => array (size=1) 0 => string 'e' (length=1) 如果你指定了 FALSE ,那每个结果数组将用从零开始的新数字索引。默认值是 FALSE 。 var_dump ( array_chunk ( $input_array, true )); array (size=3) 0 => array (size=2) 0 => string 'a' (length=1) 1 => string 'b' (length=1) 1 => array (size=2) 2 => string 'c' (length=1) 3 => string 'd' (length=1) 2 => array (size=1) 4 => string 'e' (length=1) 设为 TRUE ,可以使 PHP 保留输入数组中原来的键名。 //返回数组中特定的一列 array_column($input,$column_key,[index_key]); $column_key:需要返回值的列 $index_key:如果是int,则是索引数组 //合并数组 array_combine($a,$b); 前面数组的值做键名,后面数组的值做值 如果数组的元素个数不一样,则会有warning 如果数组维数不一样,能合并成功,但是会有Notice array (size=3) 'red' => string 'avocado' (length=7) 'yellow' => string 'apple' (length=5) 'Array' => string 'banana' (length=6) //多维数组合并会被认为是一个Array //统计数组中各个值出现的次数