过滤此多维数组以获取['virtual'] == true
的数组的最明智的方法是什么?
array (size=3)
0 =>
array (size=13)
'name' => string 'name' (length=4)
'label' => string 'Nombre' (length=6)
'sortable' => string 'true' (length=4)
'property_to_show' => boolean false
'image' => boolean false
'virtual' => boolean false <<<<<<<<<
'filter_parameter' => boolean false
'link' => boolean false
'entity' => boolean false
'boolean' => boolean false
'route_parameters' => string 'id' (length=2)
'text' => string '' (length=0)
'route' => string '' (length=0)
1 =>
array (size=14)
'virtual' => string 'true' (length=4) <<<<<<<<<<<
'label' => string 'Usuarios' (length=8)
'link' => boolean true
'class' => string 'DefaultBundle:User' (length=18)
'entity' => string 'User' (length=4)
'filter_parameter' => string 'company' (length=7)
'text' => string 'ver' (length=3)
'sortable' => boolean false
'name' => string '' (length=0)
'property_to_show' => boolean false
'image' => boolean false
'boolean' => boolean false
'route_parameters' => string 'id' (length=2)
'route' => string '' (length=0)
2 =>
array (size=14)
'virtual' => string 'true' (length=4) <<<<<<<<
'label' => string 'Productos exclusivos' (length=20)
'link' => boolean true
'class' => string 'DefaultBundle:Product' (length=21)
'entity' => string 'Product' (length=7)
'filter_parameter' => string 'company' (length=7)
'text' => string 'ver' (length=3)
'sortable' => boolean false
'name' => string '' (length=0)
'property_to_show' => boolean false
'image' => boolean false
'boolean' => boolean false
'route_parameters' => string 'id' (length=2)
'route' => string '' (length=0)
答案 0 :(得分:3)
您可以使用数组过滤器:
array_filter($array, function($value) {
return !empty($value['virtual']);
});