2016-06-30 14 views
0

['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) 
+1

?また、 '' virtual '=>文字列' 0.00'' ...? – RomanPerekhrest

答えて

3

あなたは、このために、アレイフィルタを使用することができます必要があります ` '仮想' =>文字列は「治療することfalse'`方法

array_filter($array, function($value) { 
    return !empty($value['virtual']); 
}); 
+1

'!empty($ value ['virtual'])' '$ value ['virtual']'が真であることを既にチェックしています –

+0

ああ、修正します:) – Farkie

関連する問題