如果键有价值

Rya*_*yan 0 php arrays

我有一个数组,$ data,打印时看起来像这样:

[1] => Array 
    [type] => link
[2] => Array
    [type] => photo
[3] => Array
    [type] => video
Run Code Online (Sandbox Code Playgroud)

我有$ data的foreach语句,所以每个$ data都有一个[type]键.我需要能够检查[type]键的值是否为'link',否则为'photo'的值,否则为'video'的值.

任何帮助都会很棒.我尝试了array_key_exists,但这只是检查数据字符串中是否存在密钥.

Exp*_*lls 5

foreach ($data as $datum) {
   switch ($datum['type']) {
      case 'link':
         //fill in
         break;
      case 'photo':
         //fill in
         break;
      case 'video':
         //fill in
         break;
      default:
   }
}
Run Code Online (Sandbox Code Playgroud)