Collections Flashcards
1
Q
Collect Method Map method
A
$array =["john","cathy","mery"]; $collections = collect($array); $result = $collections->map(function ($value){ return strtoupper($value); }); output :["JOHN","CATHY"...] OR
$result = collect($array)->map(function ($value){ return strtoupper($value); }); echo $result;
2
Q
Reject method
A
$array =[20,30,50]; $result = collect($array)->reject(function($value){ return $value>30; }); echo $result;
output : 20,30
3
Q
contains method
A
$array =[20,30,50]; $result = collect($array)->contains(function($value,$key){ return $value==30; }); echo $result;
output:1 (means true)
4
Q
looping array
A
$array =[20,30,50]; $result = collect($array)->each(function($value,$key){ return $value; }); echo $result;
5
Q
filter method
A
$array =[20,30,50]; $result = collect($array)->filter(function($value,$key){ return $value<50; }); echo $result;
output 20,30