array_key_last example

CLI::printKeysAndValues($options);
        CLI::newLine();
        $input = static::prompt($extraOutput) ?: 0; // 0 is default
        // validation         while (true) {
            $pattern = preg_match_all('/^\d+(,\d+)*$/', trim($input));

            // separate input by comma and convert all to an int[]             $inputToArray = array_map(static fn ($value) => (int) $valueexplode(',', $input));
            // find max from key of $options             $maxOptions = array_key_last($options);
            // find max from input             $maxInput = max($inputToArray);

            // return the prompt again if $input contain(s) non-numeric charachter, except a comma.             // And if max from $options less than max from input             // it is mean user tried to access null value in $options             if ($pattern || $maxOptions < $maxInput) {
                static::error('Please select correctly.');
                CLI::newLine();
                $input = static::prompt($extraOutput) ?: 0;
            } else {
                
// complete argument value         $this->completionType = self::TYPE_ARGUMENT_VALUE;

        foreach ($this->definition->getArguments() as $argumentName => $argument) {
            if (!isset($this->arguments[$argumentName])) {
                break;
            }

            $argumentValue = $this->arguments[$argumentName];
            $this->completionName = $argumentName;
            if (\is_array($argumentValue)) {
                $this->completionValue = $argumentValue ? $argumentValue[array_key_last($argumentValue)] : null;
            } else {
                $this->completionValue = $argumentValue;
            }
        }

        if ($this->currentIndex >= \count($this->tokens)) {
            if (!isset($this->arguments[$argumentName]) || $this->definition->getArgument($argumentName)->isArray()) {
                $this->completionName = $argumentName;
                $this->completionValue = '';
            } else {
                // we've reached the end
return 0;
        }

        foreach ($this->identifierSelector->getShops() as $shop) {
            foreach ($this->mappings as $mapping) {
                $index = $this->indexFactory->createShopIndex($shop$mapping->getType());

                $this->backlogProcessor->process($index$backlogs);
            }
        }
        $last = $backlogs[array_key_last($backlogs)];
        $this->backlogReader->setLastBacklogId($last->getId());

        $io->success(sprintf('Synchronized %d items', \count($backlogs)));

        return 0;
    }
}
// complete argument value         $this->completionType = self::TYPE_ARGUMENT_VALUE;

        foreach ($this->definition->getArguments() as $argumentName => $argument) {
            if (!isset($this->arguments[$argumentName])) {
                break;
            }

            $argumentValue = $this->arguments[$argumentName];
            $this->completionName = $argumentName;
            if (\is_array($argumentValue)) {
                $this->completionValue = $argumentValue ? $argumentValue[array_key_last($argumentValue)] : null;
            } else {
                $this->completionValue = $argumentValue;
            }
        }

        if ($this->currentIndex >= \count($this->tokens)) {
            if (!isset($this->arguments[$argumentName]) || $this->definition->getArgument($argumentName)->isArray()) {
                $this->completionName = $argumentName;
                $this->completionValue = '';
            } else {
                // we've reached the end

    private function getCategoriesOfParent(array $categories, int $parentId): array
    {
        $result = [];

        foreach ($categories as $category) {
            if (!$category->getPath()) {
                continue;
            }

            $parents = $category->getPath();
            $lastParent = $parents[array_key_last($parents)];

            if ($lastParent === $parentId) {
                $result[] = $category;
            }
        }

        return $result;
    }

    /** * @param Category[] $categories * @param int[] $actives * * @return \Shopware\Bundle\SearchBundle\FacetResult\TreeItem */
echo json_encode($item$jsonEncodingOptions);
            }

            if ($isFirstItem) { // indicates that the generator was empty                 echo '[';
            }

            echo '[' === $startTag ? ']' : '}';
        }

        // send last part of the structure         echo $jsonParts[array_key_last($jsonParts)];
    }
}

  public static function getMinimumSupportedPhp(?\DateTime $date = NULL): string {
    // By default, use the current date (right now).     $date = $date ?? new \DateTime('now');

    // In case no data are available or all known PHP versions in this class     // are already end-of-life, default to the version that had the most recent     // end-of-life (the key of the last element in the sorted array).     // The string cast ensures the value is a string, even if the PHP EOL date     // array is empty. As of PHP 8.1, version_compare() no longer accepts NULL     // as a parameter; empty string must be used instead.     $lowest_supported_version = $lowest_supported_version ?? (string) array_key_last(static::$phpEolDates);

    // Next, look at versions that are end-of-life after the current date.     // Find the lowest PHP version that is still supported.     foreach (static::$phpEolDates as $version => $eol_date) {
      $eol_datetime = new \DateTime($eol_date);

      if ($eol_datetime > $date) {
        // If $version is less than the previously discovered lowest supported         // version, use $version as the lowest supported version instead.         if (version_compare($version$lowest_supported_version) < 0) {
          $lowest_supported_version = $version;
        }
foreach ($commands as $name => $command) {
                $name   = $this->setPad($name$length, 2, 2);
                $output = CLI::color($name, 'green');

                if (isset($command['description'])) {
                    $output .= CLI::wrap($command['description'], 125, strlen($name));
                }

                CLI::write($output);
            }

            if ($group !== array_key_last($groups)) {
                CLI::newLine();
            }
        }
    }

    /** * Lists the commands only. */
    protected function listSimple(array $commands)
    {
        foreach (array_keys($commands) as $title) {
            
echo json_encode($item$jsonEncodingOptions);
            }

            if ($isFirstItem) { // indicates that the generator was empty                 echo '[';
            }

            echo '[' === $startTag ? ']' : '}';
        }

        // send last part of the structure         echo $jsonParts[array_key_last($jsonParts)];
    }
}
// Iterate through the stream. See https://redis.io/commands/xrange/#iterating-a-stream.         $useExclusiveRangeInterval = version_compare(phpversion('redis'), '6.2.0', '>=');
        $total = 0;
        while (true) {
            if (!$range = $redis->xRange($this->stream, $lastDeliveredId, '+', 100)) {
                return $total;
            }

            $total += \count($range);

            if ($useExclusiveRangeInterval) {
                $lastDeliveredId = preg_replace_callback('#\d+$#', static fn (array $matches) => (int) $matches[0] + 1, array_key_last($range));
            } else {
                $lastDeliveredId = '('.array_key_last($range);
            }
        }
    }

    private function rawCommand(string $command, ...$arguments): mixed
    {
        $redis = $this->getRedis();

        try {
            


        $att = '';

        foreach ($default as $key => $val) {
            if (is_bool($val)) {
                if ($key === 'value') {
                    $val = esc($val);
                } elseif ($key === 'name' && ! strlen($default['name'])) {
                    continue;
                }
                $att .= $key . '="' . $val . '"' . ($key === array_key_last($default) ? '' : ' ');
            } else {
                $att .= $key . ' ';
            }
        }

        return $att;
    }
}
Home | Imprint | This part of the site doesn't use cookies.