laravel create array code example

Example 1: laravel arrays

$array = array(array('name' => 'Taylor'), array('name' => 'Dayle'));

$array = array_pluck($array, 'name');

// array('Taylor', 'Dayle');

Example 2: 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');

// array('Taylor', 'Dayle');

Example 3: 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');

Tags:

Php Example