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;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Reject method

A
$array =[20,30,50];
    $result = collect($array)->reject(function($value){
        return $value>30;
    });
    echo $result;

output : 20,30

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

looping array

A
$array =[20,30,50];
    $result = collect($array)->each(function($value,$key){
      return $value;
    });
    echo $result;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

filter method

A
$array =[20,30,50];
    $result = collect($array)->filter(function($value,$key){
        return $value<50;
    });
    echo $result;

output 20,30

How well did you know this?
1
Not at all
2
3
4
5
Perfectly