We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Phalcon Filters

Hi,

I am trying to get the value through Phalcon resultset filter.

$result = $params['resultset']->filter(function($object) {
    if ($object->$params['key'] == $params['value'] ) { 
        print $params['key']; 
        return $object; 
    }
});

Can you suggest me how do I pass the $params inside the filter function. Am I doing correct ?

Raja K



98.9k
edited Apr '15

This way:

$result = $params['resultset']->filter(function($object) use ($params) {
    if ($object->$params['key'] == $params['value'] ) { 
        print $params['key']; 
        return $object; 
    }
});