I have the nested array ot transactions. One transaction has those elements 0=TransId, 1=ClientId, 2 = TransactionType, 4=Quantity:
$transactions = [
[1,'CLIENT1','BUY',45.12],
[7,'CLIENT2','BUY',25.15],
[11,'CLIENT3','SELL',784.25],
[14,'CLIENT1','SELL',7.04],
[19,'CLIENT1','BUY',21.12],
[21,'CLIENT2','SELL',14.12],
[27,'CLIENT3','BUY',15.27]
];
I have another array, which represents Ids of VIP clients:
$vipClients = ['CLIENT2','CLIENT3'];
I am able to compute an array with transactions of VIP clients by means of foreach loop:
$vipTransactions = [];
foreach ($transactions as $transaction) {
if (in_array($transaction[1], $vipClients)) {
array_push($vipTransactions, $transaction);
}
}
var_dump($vipTransactions);
I prefer to use php array functions instead of a foreach loop. Can you suggest me, how to filter nested array and value of nested segment, which will be filtered by existing value in other array? I want to use only array functions, not loops.