在2D数组中搜索... php

Thi*_*ijs 2 php multidimensional-array array-key

我有这个数组:

$ Fruit = array()

$ Fruit [$ species] [$ property] = $ value

Array
(
    [Apple] => Array
        (
            [Green] => 4
            [Spots] => 3
            [Red] => 3
            [Spots] => 2
        )
Run Code Online (Sandbox Code Playgroud)

现在我想搜索第二个数组中是否存在键...

我试过这个:

if (!array_key_exists($property, $Fruit->$species))
Run Code Online (Sandbox Code Playgroud)

但它不起作用......

有人知道如何搜索阵列数组......?

此致,Thijs

dec*_*eze 6

array_key_exists($property, $Fruit[$species])
Run Code Online (Sandbox Code Playgroud)

->用于对象,[]用于写入和读取数组.

顺便说一下,除非你的价值观可以,否则null我建议isset不要array_key_exists:

isset($Fruit[$species][$property])
Run Code Online (Sandbox Code Playgroud)

应该更直观.