duanhuanbo5225
2018-08-10 04:28
浏览 68
已采纳

如何根据无密钥多维数组中的相邻键获取特定值?

Consider the following array:

$serviceNames =  array(
    0    =>  array(
        'language'    => 'en',
        'value'       => 'something',
        'type'        => 'name',
    ),
    1    =>  array(
        'language'    => 'fi',
        'value'       => 'jotain',
        'type'        => 'name',
    ),
    2    =>  array(
        'language'    => 'sv',
        'value'       => 'någonting',
        'type'        => 'name',
    ),
);

I need to get the 'value' definitions based on language. The problematic part is that the array $serviceNames does not have a predefined length (comes originally as a JSON file from an API), and the items can come in any order (in my example it goes like en, fi, sv, but it could be de, en, sv, fr... you get it).

If I wanted to get 'value' within the array where 'language' equals to 'en', how could I do that?

图片转代码服务由CSDN问答提供 功能建议

考虑以下数组:

  $ serviceNames = array(  
 0 =>数组(
'语言'=>'en',
'值'=>'某事',
'类型'=>'名称',
),
  1 =>数组(
'语言'=>'fi',
'值'=>'jotain',
'类型'=>'名称',
),
 2 =  >数组(
'语言'=>'sv',
'值'=>'någonting',
'类型'=>'名称',
),
); 
    
 
 

我需要根据语言获得“价值”定义。 有问题的部分是数组 $ serviceNames 没有预定义的长度(最初来自API的JSON文件),并且项目可以按任何顺序排列(在我的示例中,它类似于en ,fi,sv,但它可能是de,en,sv,fr ......你明白了。

如果我想在数组中获得'value',那就是'language' 等于'en',我怎么能这样做?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题