Supported Versions: PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8
Filters elements of an array using a callback function
<?php array_filter(array $array, ?callable $callback = null, int $mode = 0): array
<?php     {

        $rootPackageMap = array_shift($packageMap);

        if (is_array($filteredDevPackages)) {

            $packageMap = array_filter($packageMap, function ($item) use ($filteredDevPackages) {

                return !in_array($item[0]->getName(), $filteredDevPackages, true);

            });

        } elseif ($filteredDevPackages) {

            $packageMap = $this->filterPackageMap($packageMap, $rootPackage);

        }
<?php         };

        $add($rootPackage);



        return array_filter(

            $packageMap,

            function ($item) use ($include) {

                $package = $item[0];

                foreach ($package->getNames() as $name) {

                    if (isset($include[$name])) {

                        return true;

                    }

                }



                return false;

            }

        );

    }
<?php                 $extraTypes .= '|enum';

            }



            PhpFileCleaner::setTypeConfig(array_merge(['class', 'interface', 'trait'], array_filter(explode('|', $extraTypes))));

        }



        return $extraTypes;
<?php         $io = $this->getIO();



        $allowlist = array('name', 'description', 'author', 'type', 'homepage', 'require', 'require-dev', 'stability', 'license', 'autoload');

        $options = array_filter(array_intersect_key($input->getOptions(), array_flip($allowlist)));



        if (isset($options['name']) && !Preg::isMatch('{^[a-z0-9_.-]+/[a-z0-9_.-]+$}D', $options['name'])) {

            throw new \InvalidArgumentException(
<?php         $requires = array_keys($package->getRequires());



        $packageListNames = array_keys($bucket);

        $packages = array_filter(

            $repo->getPackages(),

            function ($package) use ($requires, $packageListNames) {

                return in_array($package->getName(), $requires) && !in_array($package->getName(), $packageListNames);

            }

        );



        $bucket = $this->appendPackages($packages, $bucket);
<?php         if ('json' === $format) {

            $io->write(JsonFile::encode($viewData));

        } else {

            if ($input->getOption('latest') && array_filter($viewData)) {

                if (!$io->isDecorated()) {

                    $io->writeError('Legend:');

                    $io->writeError('! patch or minor release available - update recommended');
<?php         if ($packages) {

            $allowlistPackagesWithRequirements = array_filter($packages, function ($pkg) {

                return Preg::isMatch('{\S+[ =:]\S+}', $pkg);

            });

            foreach ($this->formatRequirements($allowlistPackagesWithRequirements) as $package => $constraint) {

                $reqs[$package] = $constraint;

            }
<?php         $filteredPackages = array_filter($packages, function ($package) {

            return !in_array($package, array('lock', 'nothing', 'mirrors'), true);

        });

        $updateMirrors = $input->getOption('lock') || count($filteredPackages) != count($packages);

        $packages = $filteredPackages;
<?php             }

        } while (true);



        $packages = array_filter($packages);

        if (!$packages) {

            throw new \InvalidArgumentException('You must enter minimum one package.');

        }
<?php         if ($packages = $repositorySet->findPackages($packageName, $constraint)) {

            $rootReqs = $repositorySet->getRootRequires();

            if (isset($rootReqs[$packageName])) {

                $filtered = array_filter($packages, function ($p) use ($rootReqs, $packageName) {

                    return $rootReqs[$packageName]->matches(new Constraint('==', $p->getVersion()));

                });

                if (0 === count($filtered)) {

                    return array("- Root composer.json requires $packageName".self::constraintToText($constraint) . ', ', 'found '.self::getPackageList($packages, $isVerbose, $pool, $constraint).' but '.(self::hasMultipleNames($packages) ? 'these conflict' : 'it conflicts').' with your root composer.json require ('.$rootReqs[$packageName]->getPrettyString().').');

                }
<?php             if ($lockedPackage) {

                $fixedConstraint = new Constraint('==', $lockedPackage->getVersion());

                $filtered = array_filter($packages, function ($p) use ($fixedConstraint) {

                    return $fixedConstraint->matches(new Constraint('==', $p->getVersion()));

                });

                if (0 === count($filtered)) {

                    return array("- Root composer.json requires $packageName".self::constraintToText($constraint) . ', ', 'found '.self::getPackageList($packages, $isVerbose, $pool, $constraint).' but the package is fixed to '.$lockedPackage->getPrettyVersion().' (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.');

                }
<?php                 }

            }



            $nonLockedPackages = array_filter($packages, function ($p) {

                return !$p->getRepository() instanceof LockArrayRepository;

            });



            if (!$nonLockedPackages) {

                return array("- Root composer.json requires $packageName".self::constraintToText($constraint) . ', ', 'found '.self::getPackageList($packages, $isVerbose, $pool, $constraint).' in the lock file but not in remote repositories, make sure you avoid updating this package to keep the one from the lock file.');
<?php                     return 'No package found to satisfy root composer.json require '.$packageName.($constraint ? ' '.$constraint->getPrettyString() : '');

                }



                $packagesNonAlias = array_values(array_filter($packages, function ($p) {

                    return !($p instanceof AliasPackage);

                }));

                if (count($packagesNonAlias) === 1) {

                    $package = $packagesNonAlias[0];

                    if ($request->isLockedPackage($package)) {
<?php                 if (!$node->getRule()->isDisabled() && !$decisions->satisfy($otherWatch)) {

                    $ruleLiterals = $node->getRule()->getLiterals();



                    $alternativeLiterals = array_filter($ruleLiterals, function ($ruleLiteral) use ($literal, $otherWatch, $decisions) {

                        return $literal !== $ruleLiteral &&

                            $otherWatch !== $ruleLiteral &&

                            !$decisions->conflict($ruleLiteral);

                    });



                    if ($alternativeLiterals) {

                        reset($alternativeLiterals);
<?php             if ($isDownloadsModifyingPlugin || count(array_intersect($package->getNames(), $dlModifyingPluginRequires))) {


                $requires = array_filter(array_keys($package->getRequires()), function ($req) {

                    return !PlatformRepository::isPlatformPackage($req);

                });




                if ($isDownloadsModifyingPlugin && !count($requires)) {