PHP get modified array that matches a certain value -


i have array of arrays below:

        array (     [0] => array         (             [id] => 1             [uid] => 746             [lid] => 748         )     [1] => array         (             [id] => 6             [uid] => 746             [lid] => 744         )     [2] => array         (             [id] => 11             [uid] => 749             [lid] => 743         )   ) 

what want modified array has uid of 746. result expect is:

array     (         [0] => array             (                 [id] => 1                 [uid] => 746                 [lid] => 748             )         [1] => array             (                 [id] => 6                 [uid] => 746                 [lid] => 744             )       ) 

is there quick way rather loop through each element , save matching array return array?

there's no way without inspecting each element. being said can use array_filter (though loop behind scenes):

$arr = array_filter($arr, function($item){     return $item['uid'] == 746; }); 

prior php 5.3.0 have declare function:

function filter746($item){     return $item['uid'] == 746; } $arr = array_filter($arr, 'filter746'); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -