An example:
$result = [];
foreach($ret as $item) {
$result[] = $item['id'];
}
return $result;
Is there a one-liner in PHP that can do this? It very hard to search on google for "keys in arrays" because it's very vague...
An example:
$result = [];
foreach($ret as $item) {
$result[] = $item['id'];
}
return $result;
Is there a one-liner in PHP that can do this? It very hard to search on google for "keys in arrays" because it's very vague...
PHP >= 5.5.0 required for array_column
:
$result = array_column($ret, 'id');
Other than that your loop is as good as it gets.