I have this array:
$transfers =
Array
(
[0] => Array
(
[agency_to_id] => 8
[agency_name] => 3.1 SUCURSAL BRASILIA
[product_id] => 415
[product_code] => 111021
[product_name] => PAN FELIPE POR KILO
[ptype_id] => 54
[ptype_name] => 1.1.01.1 PANADERIA X KILO
[catalog_id] => 1
[subject_id] => 3
[label_id] => 300000002
[total_quantity] => 12
)
[1] => Array
(
[agency_to_id] => 9
[agency_name] => 4.1 SUCURSAL CENTRO
[product_id] => 415
[product_code] => 111021
[product_name] => PAN FELIPE POR KILO
[ptype_id] => 54
[ptype_name] => 1.1.01.1 PANADERIA X KILO
[catalog_id] => 1
[subject_id] => 3
[label_id] => 300000002
[total_quantity] => 8
)
[2] => Array
(
[agency_to_id] => 8
[agency_name] => 3.1 SUCURSAL BRASILIA
[product_id] => 416
[product_code] => 111024
[product_name] => GALLETA POR KILO
[ptype_id] => 54
[ptype_name] => 1.1.01.1 PANADERIA X KILO
[catalog_id] => 1
[subject_id] => 3
[label_id] => 300000002
[total_quantity] => 1.6
)
[3] => Array
(
[agency_to_id] => 8
[agency_name] => 3.1 SUCURSAL BRASILIA
[product_id] => 418
[product_code] => 111028
[product_name] => PAN INTEGRAL POR KILO
[ptype_id] => 54
[ptype_name] => 1.1.01.1 PANADERIA X KILO
[catalog_id] => 1
[subject_id] => 3
[label_id] => 300000002
[total_quantity] => 200
)
)
And I want to get all the keys of this array that match a specific subarray value, for example I want to get the keys that match [product_id] => 415
and I should get the the keys 0 and 1
I have tried with array_keys but it does not work.
EDIT:
foreach ($transfers $key => $transfer) {
$found_keys = array_keys($transfers, $transfer['product_id']);
}
So, your answer, devolves an empty array
foreach ($transfers $key => $transfer) {
$filteredKeys = array_keys(array_filter($transfers,
function($item) {
return $item['product_id'] === $transfer['product_id'];
}));
}
Can you help me please. Thank you