The example in this article describes the usage of php array key values. Share it with everyone for your reference. The specific analysis is as follows:
Look at an array first:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
$switching = array(
10, // key = 0
5 => 6,
3 => 7,
'a' => 4,
11, // key = 6 (整个数组中整型键索引最大的值是5)
'8' => 2, // key = 8 (字符串健'8'转换为8)
'02' => 77, // key = '02'(注意不是2)
0 => 12
/*前面值为10的键被赋予0,而后面重新定义了0键的值为12,
从而覆盖了前面默认的0键值*/
);
// empty array
$empty = array();
?>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<🎜>$switching = array(<🎜>
<🎜>10, // key = 0<🎜>
<🎜>5 => 6,<🎜>
<🎜>3 => 7,<🎜>
<🎜>'a' => 4,<🎜>
<🎜>11, // key = 6 (the maximum value of the integer key index in the entire array is 5)<🎜>
<🎜>'8' => 2, // key = 8 (string key '8' is converted to 8)<🎜>
<🎜>'02' => 77, // key = '02' (note not 2) <🎜>
<🎜>0 => 12<🎜>
<🎜>/*The key with the previous value 10 is assigned 0, and the value of the 0 key is redefined later to 12, <🎜>
<🎜>Thus overwriting the previous default key value of 0*/<🎜>
<🎜>);<🎜>
<🎜>// empty array<🎜>
<🎜>$empty = array();<🎜>
<🎜>?>
|
If printed with print_r($switching), the result is:
Array ( [0] => 12 [5] => 6 [3] => 7 [a] => 4 [6] => 11 [8] => 2 [02] => 77 )
Note that the two-digit number 02 is listed behind.
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/961775.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/961775.htmlTechArticleExample analysis of php array key value usage This article mainly introduces the usage of php array key value and an example analysis of php array The system automatic allocation principle and usage skills of medium key values have certain reference...