在php中查找多维数组中有效键的数量

时间:2017-03-31 03:54:16

标签: php arrays validation multidimensional-array

我需要知道有多少数组具有有效键,多维数组中有多少个数组具有有效键。让我解释一下:

输入:

Array
(
    [65] => Array
        (
            [1] => Array
                (
                    [0] => Array
                        (
                            [mediumid] => 65
                            [mediumname] => VINYL
                            [trackid] => 525
                            [trackposition] => 1
                            [tracklocation] => SIDE A
                            [tracknumber] => 1
                            [trackname] => I love u
                        )

                    [1] => Array
                        (
                            [mediumid] => 65
                            [mediumname] => VINYL
                            [trackid] => 526
                            [trackposition] => 1
                            [tracklocation] => SIDE A
                            [tracknumber] => 2
                            [trackname] => Sun is yellow
                        )

                )

            [2] => Array
                (
                    [0] => Array
                        (
                            [mediumid] => 65
                            [mediumname] => VINYL
                            [trackid] => 527
                            [trackposition] => 2
                            [tracklocation] => SIDE B
                            [tracknumber] => 1
                            [trackname] => Car red
                        )

                    [1] => Array
                        (
                            [mediumid] => 65
                            [mediumname] => VINYL
                            [trackid] => 528
                            [trackposition] => 2
                            [tracklocation] => SIDE B
                            [tracknumber] => 2
                            [trackname] => Lady in red
                        )

                )

        )

     [769] => Array
        (
            [] => Array
                (
                    [0] => Array
                        (
                            [mediumid] => 769
                            [mediumname] => DVD
                            [trackid] =>
                            [trackposition] =>
                            [tracklocation] => 
                            [tracknumber] =>
                            [trackname] =>
                        )
                )
        ) 
    )

mediums [65] next数组包含2个有效键(1和2)。 mediums [769] next数组不包含有效键

因此,只有medium [65]包含有效密钥,因此有效密钥的数组总数= 1。 我需要找到这个总数。怎么样?

我尝试使用array_keys和array_filter,没有成功(或者我做错了)

1 个答案:

答案 0 :(得分:1)

PHP code demo

 s.StudentLocation.URL.Equals(StudentUrl,StringComparison.OrdinalIgnoreCase)