Answers for "pluck array of collection"

PHP
0

php pluck from array of objects

$cats = [
  0 => { 'id': 15 },
  1 => { 'id': 18 },
  2 => { 'id': 23 }
]
  
$idCats = array_column($cats, 'id');
Posted by: Guest on November-11-2021
3

pluck array in laravel

$users = User::all()->pluck('field_name');
//for keys instead of [User::all()->pluck('id');] use
$user_ids = User::all()->modelKeys();
Posted by: Guest on February-12-2021

Browse Popular Code Answers by Language