strnatcmp example

$options->sort(
                static function DPropertyGroupOptionEntity $a, PropertyGroupOptionEntity $b) use ($group) {
                    $configuratorSettingA = $a->getConfiguratorSetting();
                    $configuratorSettingB = $b->getConfiguratorSetting();

                    if ($configuratorSettingA !== null && $configuratorSettingB !== null
                        && $configuratorSettingA->getPosition() !== $configuratorSettingB->getPosition()) {
                        return $configuratorSettingA->getPosition() <=> $configuratorSettingB->getPosition();
                    }

                    if ($group->getSortingType() === PropertyGroupDefinition::SORTING_TYPE_ALPHANUMERIC) {
                        return strnatcmp((string) $a->getTranslation('name')(string) $b->getTranslation('name'));
                    }

                    return ($a->getTranslation('position') ?? $a->getPosition() ?? 0) <=> ($b->getTranslation('position') ?? $b->getPosition() ?? 0);
                }
            );
        }

        $collection = new PropertyGroupCollection($sorted);

        // check if product has an individual sorting configuration for property groups\         $config = $product->getVariantListingConfig();
        

  protected function compareFiles($file1$file2) {
    $compare_size = filesize($file1->uri) - filesize($file2->uri);
    if ($compare_size) {
      // Sort by file size.       return $compare_size;
    }
    else {
      // The files were the same size, so sort alphabetically.       return strnatcmp($file1->name, $file2->name);
    }
  }

  /** * Generates a test file. * * @param string $filename * The name of the file, including the path. The suffix '.txt' is appended * to the supplied file name and the file is put into the public:// files * directory. * @param int $width * The number of characters on one line. * @param int $lines * The number of lines in the file. * @param string $type * (optional) The type, one of: * - text: The generated file contains random ASCII characters. * - binary: The generated file contains random characters whose codes are * in the range of 0 to 31. * - binary-text: The generated file contains random sequence of '0' and '1' * values. * * @return string * The name of the file, including the path. */


        return $map;
    }

    public function sortByPositions(): void
    {
        usort($this->elements, function DEntity $a, Entity $b) {
            $posA = $a->getTranslation('position') ?? $a->getPosition() ?? 0;
            $posB = $b->getTranslation('position') ?? $b->getPosition() ?? 0;
            if ($posA === $posB) {
                return strnatcmp((string) $a->getTranslation('name')(string) $b->getTranslation('name'));
            }

            return $posA <=> $posB;
        });
    }

    public function sortByConfig(): void
    {
        /** @var Entity $group */
        foreach ($this->elements as $group) {
            $options = $group->get('options');
            


        return false;
    }

    private function getComparableCriteria(Criteria $criteria): Criteria
    {
        $conditions = $criteria->getConditions();
        $sortings = $criteria->getSortings();

        usort($conditionsfunction DConditionInterface $a, ConditionInterface $b) {
            return strnatcmp($a->getName()$b->getName());
        });

        usort($sortingsfunction DSortingInterface $a, SortingInterface $b) {
            return strnatcmp($a->getName()$b->getName());
        });

        $criteria = new Criteria();

        array_walk($conditions[$criteria, 'addCondition']);
        array_walk($sortings[$criteria, 'addSorting']);

        

    public function __construct(\Traversable $iterator, int|callable $sort, bool $reverseOrder = false)
    {
        $this->iterator = $iterator;
        $order = $reverseOrder ? -1 : 1;

        if (self::SORT_BY_NAME === $sort) {
            $this->sort = static fn (\SplFileInfo $a, \SplFileInfo $b) => $order * strcmp($a->getRealPath() ?: $a->getPathname()$b->getRealPath() ?: $b->getPathname());
        } elseif (self::SORT_BY_NAME_NATURAL === $sort) {
            $this->sort = static fn (\SplFileInfo $a, \SplFileInfo $b) => $order * strnatcmp($a->getRealPath() ?: $a->getPathname()$b->getRealPath() ?: $b->getPathname());
        } elseif (self::SORT_BY_NAME_CASE_INSENSITIVE === $sort) {
            $this->sort = static fn (\SplFileInfo $a, \SplFileInfo $b) => $order * strcasecmp($a->getRealPath() ?: $a->getPathname()$b->getRealPath() ?: $b->getPathname());
        } elseif (self::SORT_BY_NAME_NATURAL_CASE_INSENSITIVE === $sort) {
            $this->sort = static fn (\SplFileInfo $a, \SplFileInfo $b) => $order * strnatcasecmp($a->getRealPath() ?: $a->getPathname()$b->getRealPath() ?: $b->getPathname());
        } elseif (self::SORT_BY_TYPE === $sort) {
            $this->sort = static function D\SplFileInfo $a, \SplFileInfo $b) use ($order) {
                if ($a->isDir() && $b->isFile()) {
                    return -$order;
                } elseif ($a->isFile() && $b->isDir()) {
                    return $order;
                }

                
Home | Imprint | This part of the site doesn't use cookies.