0

次のような配列があります。

Array
(
    [100] => Array
        (
            [room_id] => 100
            [name] => Town Center
        )

    [110] => Array
        (
            [room_id] => 110
            [name] => Coffee Shop
            [pin_id] => 7146
            [pin_x] => 570
            [pin_y] => 150
        )
)

「pin_id」値がある場合、特定の値のキーを見つける方法があるかどうか疑問に思っていました。例えば:

Array
(
    [100] => Array
        (
            [room_id] => 100
            [name] => Town Center
        )

    [110] => Array                    <- I want to get this key "110"             
        (                                 
            [room_id] => 110          
            [name] => Coffee Shop     
            [pin_id] => 7146          <- Because "pin_id" is here
            [pin_x] => 570
            [pin_y] => 150
        )
)
4

1 に答える 1

1

配列をループに渡して使用する必要がありますarray_key_exists

function makeHappen($argument){
  //Array
    foreach ($argument as $val) {
      if(array_key_exists($val, $array)){
            //if key exists, do something
      }
    }
}
echo makeHappen('pin_id');
于 2013-03-10T02:10:52.247 に答える