所以,
在我的代码中,我的一个变量碰巧包含null,这给了我一些相当难以跟踪的问题,特别是它返回了一些奇怪的东西。
下面是同一个数组的print_r,第一个用print_r($array['key'][null])
调用null
,第二个print_r($array['key'])
没有null
键,那么第一个是什么阵列
第一
Array
(
[parent_access] => 1
[seasons] => Array
(
[1] => Array
(
[parent_access] => 1
[rounds] => Array
(
[5] => Array
(
[direct_access] => 1
)
)
)
)
)
第二(注意,下面的整个数组可以在https://gist.github.com/4679128看到)
Array
(
[1] => Array
(
[id] => 1
[type] => competition
[status] => 0
[child_access] =>
[direct_access] => 1
[parent_access] =>
[seasons] => Array
(
[1] => Array
(
[id] => 1
[type] => season
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
[rounds] => Array
(
[1] => Array
(
[id] => 1
[type] => round
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
[games] => Array
(
[1] => Array
(
[id] => 1
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[11] => Array
(
[id] => 11
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[21] => Array
(
[id] => 21
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[31] => Array
(
[id] => 31
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
)
)
[5] => Array
(
[id] => 5
[type] => round
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
[games] => Array
(
[5] => Array
(
[id] => 5
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[15] => Array
(
[id] => 15
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[25] => Array
(
[id] => 25
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[35] => Array
(
[id] => 35
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
)
)
[8] => Array
(
[id] => 8
[type] => round
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
[games] => Array
(
[8] => Array
(
[id] => 8
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[18] => Array
(
[id] => 18
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[28] => Array
(
[id] => 28
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[38] => Array
(
[id] => 38
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
)
)
[10] => Array
(
[id] => 10
[type] => round
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
[games] => Array
(
[10] => Array
(
[id] => 10
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[20] => Array
(
[id] => 20
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[30] => Array
(
[id] => 30
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[40] => Array
(
[id] => 40
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
)
)
)
)
[2] => Array
(
[id] => 2
[type] => season
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
[rounds] => Array
(
[2] => Array
(
[id] => 2
[type] => round
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
[games] => Array
(
[2] => Array
(
[id] => 2
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[12] => Array
(
[id] => 12
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[22] => Array
(
[id] => 22
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[32] => Array
(
[id] => 32
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
)
)
[6] => Array
(
[id] => 6
[type] => round
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
[games] => Array
(
[6] => Array
(
[id] => 6
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[16] => Array
(
[id] => 16
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[26] => Array
(
[id] => 26
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[36] => Array
(
[id] => 36
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
)
)
[9] => Array
(
[id] => 9
[type] => round
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
[games] => Array
(
[9] => Array
(
[id] => 9
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[19] => Array
(
[id] => 19
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[29] => Array
(
[id] => 29
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
[39] => Array
(
[id] => 39
[type] => game
[status] => 1
[child_access] => 1
[direct_access] =>
[parent_access] =>
)
)
)
)
)
)
)
[2] => Array
(
[id] => 2
[type] => competition
[status] => 1
[child_access] =>
[direct_access] =>
[parent_access] =>
[seasons] => Array
(
[3] => Array
(
[id] => 3
[type] => season
[status] => 1
[child_access] =>
[direct_access] =>
[parent_access] =>
[rounds] => Array
(
答案 0 :(得分:2)
因此null
被转换为空字符串。
http://php.net/manual/en/language.types.array.php
Null将被强制转换为空字符串,即密钥null实际上将存储在“”。
下