in array laravel code example
Example 1: laravel where in array
$items = DB::table('items')->whereIn('id',[1,2,..])->get();
Example 2: laravel where in array
$items = Item::whereIn('id', [1,2,..])->get();
Example 3: laravel arrays
$array = array(array('name' => 'Taylor'), array('name' => 'Dayle'));
$array = array_pluck($array, 'name');
Example 4: laravel take value from different array by key
$array = array(
array('developer' => array('name' => 'Taylor')),
array('developer' => array('name' => 'Dayle')),
);
$array = array_fetch($array, 'developer.name');
Example 5: where is in array laravel
$items = DB::table('items')->whereIn('id', [1, 2, 3])->get();
Example 6: laravel return a single dimensional array
$catcount = 2;
$parents_ids = [];
for ($i = 0; $i < $catcount; $i++) {
$parents_ids[] = $userCategory[$i];
}
$subCats = Category::whereIn('parent_id', $parents_ids)->pluck('id');