Reputation: 5281
Is it possible to get only an n number of items using dom crawler ?
I have
`$items = $website->filter('ul.listnews li');
$items>each(function($node,$con){
}`
But I want to get only the first 5 items from the list. I tried running a for loop but I couldn't get it to work. Any ideas on how I could do it ?
Upvotes: 0
Views: 814
Reputation: 5577
You can use reduce
method in chain:
$items = $website
->filter('ul.listnews li')
->reduce(function (Crawler $node, $i) {
return $i < 5;
});
Upvotes: 1