Forum

Thread tagged as: Question, Docs

Item callback function (using 'each')

Hi,

could I double-check something with you?

Quoting the docs, in relation to using

'each' => function($item) {...

"After processing, the function must return the array."

I've been playing with this and returning nothing from the function works absolutely fine - is this by design? If so, I can use 'each' to provide some extra-fine filtering, so some items are returned, others aren't. Just thought I'd check with you before committing with my code - I don't want it to break in a future version... ;-)

This is using 2.8.31.

Duncan Revell

Duncan Revell 78 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

The idea is you get handed $item, you manipulate it, and then you return it.

If you don't return $item then that item won't be included in the result.

Duncan Revell

Duncan Revell 78 points
Registered Developer

Thanks Drew - I know that's the idea, it's just that in a current case, I can use this to provide 'extra' filtering by not returning $item.

Cheers.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Right, as I said, that's how it works.