Answer the question
In order to leave comments, you need to log in
Deleting in an array by the value of another array?
Hello.
Tell me how to quickly delete an array in a multidimensional array by value from another array.
For example:
The first array from which we will delete
array(3) {
[0]=>
array(9) {
["id"]=>
string(1) "1"
["colmn1"]=>
string(9) "TEST name"
["ticker"]=>
string(4) "TEST"
["value"]=>
string(3) "100"
["uniq_id"]=>
string(32) "51cac2ed2fee4ec3a074a9e04f89887b"
}
[1]=>
array(9) {
["id"]=>
string(1) "2"
["colmn1"]=>
string(9) "TEST2"
["ticker"]=>
string(4) "TEST2"
["value"]=>
string(3) "100"
["uniq_id"]=>
string(32) "902b29f87418415893372792d6913e31"
}
[2]=>
array(9) {
["id"]=>
string(1) "3"
["colmn1"]=>
string(9) "TEST3"
["ticker"]=>
string(4) "TEST3"
["value"]=>
string(3) "100"
["uniq_id"]=>
string(32) "76246b76f0f0423b8b7f75634afab64e"
}
}
array(2) {
[0]=>
string(22) "76246b76f0f0423b8b7f75634afab64e"
[1]=>
string(15) "902b29f87418415893372792d6913e31"
}
Answer the question
In order to leave comments, you need to log in
It is natural to use array_filter
to filter an array :
$res = array_filter(
$arr,
fn($el)=>!in_array($el["uniq_id"], $filter)
);
unset
array_diff_key(array_column($array, null, 'uniq_id'), array_flip($excludedKeys));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question