I have an array $arrItems['items'] in which 5 more arrays (associate array) and each array contain 5 element (with the keys: f_name, l_name, contact, address, seller_id).
I want to get all those arrays (from $arrItems['items']) in which element of seller_id is 1 like "seller_id"=>"1,2,3" OR "seller_id"=>"3,2,1" OR "seller_id"=>"4,6,2" OR "seller_id"=>"5,3,4" OR "seller_id"=>"2,1,2" Array given below
$currentUser=1;
$arr= array_filter($arrItems['items'], function($e) use ($currentUser) {
return in_array($currentUser, explode(",", $e["current_seller_id"]));
});
actually am apply filter on Order Items Collection. Then it filter perfectly but not set array in order grid. Order Grid is buffering not display data. When i write same code in foreach loop then data in order items grid set perfectly But my foreach loop not filter right. it return some extra array where seller_id not exist. My Foreach loop code is there :
$seller_order_arr = [];
foreach ($arrItems['items'] as $row) {
if (strpos($row['current_seller_id'] ,",") > 1 && $row['current_seller_id'] != null){
$seller_order_arr[] = $row;
}
if($row['current_seller_id'] == $currentUser){
$seller_order_arr[] = $row;
}
}
$arrItems['items'] = $seller_order_arr;
anyone help me to re-write array_filter code in foreach code.