<?php
$array = array (
0 =>
array (
'id' => 1,
'user_id' => 15,
'booked' => '2020-08-01',
'sendin' => '2020-08-03',
'pickup' => '2020-08-08',
'duration' => 5
),
1 =>
array (
'id' => 2,
'user_id' => 15,
'booked' => '2020-08-01',
'sendin' => '2020-08-03',
'pickup' => '2020-08-08',
'duration' => 5
)
);
$user_id = 15;
$ids = array_map(function ($a) { return $a['id']; },
array_filter($array,
function ($a) use ($user_id) {
return $a['user_id'] == $user_id;
})
);
print_r($ids);
$ids = array_map(function ($k) use ($array) { return $array[$k]['id']; },
array_keys(array_column($array, 'user_id'), $user_id)
);
print_r($ids);
- Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
- Array
(
[0] => 1
[1] => 2
)
Array
(
[0] => 1
[1] => 2
)
preferences:
73.29 ms | 407 KiB | 5 Q