1

所以,

在我的代码中,我的一个变量恰好包含 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
                                (
4

1 回答 1

2

http://ideone.com/pXRVKE

因此,null将转换为空字符串。

http://php.net/manual/en/language.types.array.php

Null 将被强制转换为空字符串,即键 null 将实际存储在 "" 下。

于 2013-01-31T01:24:47.167 回答