Answers for "get item from collection that match"

PHP
0

get item from collection that match

$artist = 'Vincent John Doe';

// you can filter the collection and keep only those items
// that pass a given truth test:
$art_collection = $paintings->filter(function ($painting) use ($artist) {
  return $painting->artist == $artist;
});

// you can also do a foreach
foreach($paintings as $painting) {
  if($painting->artist == $artist) {
    $art_collection[] = $painting;
  }
}
Posted by: Guest on January-14-2021

Code answers related to "get item from collection that match"

Browse Popular Code Answers by Language