从php数组中获取自定义值

时间:2018-01-11 00:26:00

标签: php arrays

我有这个大阵容:

Array ( [0] => Array ( [group_id] => 87 
[group_name] => Étel jellemzők 
[group_slug] => etel_jellemzok 
[group_desc] => [attributes] => Array ( [0] => Array ( [attr_id] => 88 
[attr_name] => csípős [attr_slug] => csipos [attr_desc] => [value] => yes ) 
[1] => Array ( [attr_id] => 89 [attr_name] => gluténmentes [attr_slug] => glutenmentes [attr_desc] => [value] => yes ) 
[2] => Array ( [attr_id] => 90 [attr_name] => tejmentes [attr_slug] => tejmentes [attr_desc] => [value] => yes ) 
[3] => Array ( [attr_id] => 91 [attr_name] => új [attr_slug] => uj [attr_desc] => [value] => yes ) ) ) 
[1] => Array ( [group_id] => 92 [group_name] => Allergének [group_slug] => allergenek [group_desc] => [attributes] => Array ( [0] => Array ( [attr_id] => 93
[attr_name] => laktóz [attr_slug] => laktoz [attr_desc] => [value] => yes )
[1] => Array ( [attr_id] => 94 [attr_name] => glutén [attr_slug] => gluten [attr_desc] => [value] => yes )
[2] => Array ( [attr_id] => 95 [attr_name] => diófélék [attr_slug] => diofelek [attr_desc] => [value] => yes )
[3] => Array ( [attr_id] => 96 [attr_name] => szója [attr_slug] => szoja [attr_desc] => [value] => yes ) ) ) )

如何仅返回所有attr_name及其值?

1 个答案:

答案 0 :(得分:1)

你可以试试这个(未经测试):

array_column($array[0]['attributes'], 'value', 'attr_name');