H.Furkan YERLİ
H.Furkan YERLİ

Reputation: 23

Combine Two Collection Laravel

I have a 2 collection. I want to combine.

$a = collect([1,2,3]);
$b = collect(['a','b','c']);

I want that ;

$c = 1-a ;

How do I combine the two?

 {{ Form::select('things', $c , NULL,NULL ['id' => 'myselect']) }}

Upvotes: 1

Views: 985

Answers (2)

Teoman Tıngır
Teoman Tıngır

Reputation: 2866

First of all, you need to combine these collections.

$a = collect([1,2,3]);
$b = collect(['a','b','c']);

$combined = $a->combine($b);

Then use map() method for manipulate your collection items

$united = $combined->map(function ($value,$key){
    return $key."-".$value;
});

Upvotes: 2

parastoo
parastoo

Reputation: 2469

  $a = collect([1,2,3]);
  $b = collect(['a','b','c']);

  $c = $a->combine($b);

  $d = $c->map(function($item, $key){
    return $item . '-' . $key;
  });

Upvotes: 1

Related Questions