I have and array of with allEntries and an array with alreadyUpdatedEntries. I would like to filter out all the alreadyUpdatedToEntries to end up with an array of notUpdatedEntries. Like how it is done in Twig.

{% set notUpdatedEntries = allEntries|without(alreadyUpdatedEntries) %}

Is there a similar Craft PHP method to do this in my plugin? Can I maybe include this in my elements criteria query?

1 Answer 1


You can use similar logic that Craft uses for the withoutFilter in CraftTwigExtension.

public function withoutFilter($arr, $exclude)
    $filteredArray = array();

    if (!is_array($exclude))
        $exclude = array($exclude);

    foreach ($arr as $key => $value)
        if (!in_array($value, $exclude))
            $filteredArray[$key] = $value;

    return $filteredArray;
  • @RitterKnight That's what I get for posting before coffee.
    – Brad Bell
    Apr 6, 2016 at 18:31
  • Been there, done that! Apr 6, 2016 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.