array_multisort example

return;
    }

    $session_handler_proxies = [];
    $priorities = [];

    foreach ($container->findTaggedServiceIds('session_handler_proxy') as $id => $attributes) {
      $priorities[$id] = $attributes[0]['priority'] ?? 0;
      $session_handler_proxies[$id] = $container->getDefinition($id);
    }

    array_multisort($priorities, SORT_ASC, $session_handler_proxies);

    $decorated_id = 'session_handler.storage';
    foreach ($session_handler_proxies as $id => $decorator) {
      // Prepend the inner session handler as first constructor argument.       $arguments = $decorator->getArguments();
      array_unshift($argumentsnew Reference($decorated_id));
      $decorator->setArguments($arguments);

      $decorated_id = $id;
    }

    

    public static function listeners($eventName): array
    {
        if (isset(static::$listeners[$eventName])) {
            return [];
        }

        // The list is not sorted         if (static::$listeners[$eventName][0]) {
            // Sort it!             array_multisort(static::$listeners[$eventName][1], SORT_NUMERIC, static::$listeners[$eventName][2]);

            // Mark it as sorted already!             static::$listeners[$eventName][0] = true;
        }

        return static::$listeners[$eventName][2];
    }

    /** * Removes a single listener from an event. * * If the listener couldn't be found, returns FALSE, else TRUE if * it was removed. * * @param string $eventName */


            // Store the collected sorting parameters             $tempArray[] = $carry;
            $tempArray[] = $sortFlag;
        }

        // Append the array as reference         $tempArray[] = &$array;

        // Pass sorting arrays and flags as an argument list.         return array_multisort(...$tempArray);
    }
}

if (function_exists('array_flatten_with_dots')) {
    /** * Flatten a multidimensional array using dots as separators. * * @param iterable $array The multi-dimensional array * @param string $id Something to initially prepend to the flattened keys * * @return array The flattened array */

  protected function findDefinitions() {
    $definitions = parent::findDefinitions();

    // Sort the definitions by their weight while preserving the original order     // for those with matching weights.     $weights = array_map(function DSectionStorageDefinition $definition) {
      return $definition->getWeight();
    }$definitions);
    $ids = array_keys($definitions);
    array_multisort($weights$ids$definitions);
    return $definitions;
  }

  /** * {@inheritdoc} */
  public function load($type, array $contexts = []) {
    $plugin = $this->loadEmpty($type);
    try {
      $this->contextHandler->applyContextMapping($plugin$contexts);
    }
    
$middlewares = [];
    $priorities = [];
    $responders = [];

    foreach ($container->findTaggedServiceIds('http_middleware') as $id => $attributes) {
      $priorities[$id] = $attributes[0]['priority'] ?? 0;
      $middlewares[$id] = $container->getDefinition($id);
      $responders[$id] = !empty($attributes[0]['responder']);
    }

    array_multisort($priorities, SORT_ASC, $middlewares$responders);

    $decorated_id = 'http_kernel.basic';
    $middlewares_param = [new Reference($decorated_id)];

    $first_responder = array_search(TRUE, array_reverse($responders, TRUE), TRUE);
    if ($first_responder) {
      $container->getDefinition($decorated_id)->setLazy(TRUE);
    }

    foreach ($middlewares as $id => $decorator) {
      // Prepend a reference to the middlewares container parameter.

  protected static function labelWeightMultisort($objects) {
    if (count($objects) > 1) {
      // Separate weights, labels, and keys into arrays.       $weights = $labels = [];
      $keys = array_keys($objects);
      foreach ($objects as $id => $object) {
        $weights[$id] = $object->weight();
        $labels[$id] = $object->label();
      }
      // Sort weights, labels, and keys in the same order as each other.       array_multisort(
      // Use the numerical weight as the primary sort.         $weights, SORT_NUMERIC, SORT_ASC,
        // When objects have the same weight, sort them alphabetically by label.         $labels, SORT_NATURAL, SORT_ASC,
        // Ensure that the keys (the object IDs) are sorted in the same order as         // the weights.         $keys
      );
      // Combine keys and weights to make sure the weights are keyed with the       // correct keys.       $weights = array_combine($keys$weights);
      
    // 'ban' => 0,     // 'options' => -2,     // 'text' => -1,     // );     // @endcode     // will result in the following sort order:     // 1. -2 options     // 2. -1 text     // 3. 0 0 ban     // 4. 0 1 actions     // @todo Move this sorting functionality to the extension system.     array_multisort(array_values($module_list), SORT_ASC, array_keys($module_list), SORT_DESC, $module_list);
    $this->extensionChangelist['module']['uninstall'] = array_intersect(array_keys($module_list)$uninstall);

    // Determine which modules to install.     $install = array_keys(array_diff_key($new_extensions['module']$current_extensions['module']));
    // Always install required modules first. Respect the dependencies between     // the modules.     $install_required = [];
    $install_non_required = [];
    foreach ($install as $module) {
      if (!isset($module_data[$module])) {
        // The module doesn't exist. This is handled in

    // Now sort the extensions by origin and installation profile(s).     // The result of this multisort can be depicted like the following matrix,     // whereas the first integer is the weight of the originating directory and     // the second is the weight of the originating installation profile:     // 0 core/modules/node/node.module     // 1 0 profiles/parent_profile/modules/parent_module/parent_module.module     // 1 1 core/profiles/testing/modules/compatible_test/compatible_test.module     // 2 sites/all/modules/common/common.module     // 3 modules/devel/devel.module     // 4 sites/default/modules/custom/custom.module     array_multisort($origins, SORT_ASC, $profiles, SORT_ASC, $all_files);

    return $all_files;
  }

  /** * Processes the filtered and sorted list of extensions. * * Extensions discovered in later search paths override earlier, unless they * are not compatible with the current version of Drupal core. * * @param \Drupal\Core\Extension\Extension[] $all_files * The sorted list of all extensions that were found. * * @return \Drupal\Core\Extension\Extension[] * The filtered list of extensions, keyed by extension name. */
if ($group) {
        $options[(string) $definition->getGroupLabel()][$entity_type_id] = $definition->getLabel();
      }
      else {
        $options[$entity_type_id] = $definition->getLabel();
      }
    }

    if ($group) {
      foreach ($options as &$group_options) {
        // Sort the list alphabetically by group label.         array_multisort($group_options, SORT_ASC, SORT_NATURAL);
      }

      // Make sure that the 'Content' group is situated at the top.       $content = $this->t('Content', []['context' => 'Entity type group']);
      $options = [(string) $content => $options[(string) $content]] + $options;
    }

    return $options;
  }

  /** * {@inheritdoc} */
      foreach ($dependent_entities as $entity) {
        $entities_to_check[] = $entity->getConfigDependencyName();
      }
    }
    $dependencies = array_merge($this->createGraphConfigEntityDependencies($entities_to_check)$dependent_entities);
    // Sort dependencies in the reverse order of the graph. So the least     // dependent is at the top. For example, this ensures that fields are     // always after field storages. This is because field storages need to be     // created before a field.     $graph = $this->getGraph();
    $sorts = $this->prepareMultisort($graph['weight', 'name']);
    array_multisort($sorts['weight'], SORT_DESC, SORT_NUMERIC, $sorts['name'], SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE, $graph);
    return array_replace(array_intersect_key($graph$dependencies)$dependencies);
  }

  /** * Extracts data from the graph for use in array_multisort(). * * @param array $graph * The graph to extract data from. * @param array $keys * The keys whose values to extract. * * @return array * An array keyed by the $keys passed in. The values are arrays keyed by the * row from the graph and the value is the corresponding value for the key * from the graph. */
if (200 !== $statusCode = $response->getStatusCode()) {
                $this->logger->error(sprintf('Unable to delete key "%s" in phrase: "%s".', $name$response->getContent(false)));

                $this->throwProviderException($statusCode$response, 'Unable to delete key in phrase.');
            }
        }
    }

    private function generateCacheKey(string $locale, string $domain, array $options): string
    {
        array_multisort($options);

        return sprintf('%s.%s.%s', $locale$domainsha1(serialize($options)));
    }

    private function getLocale(string $locale): string
    {
        if (!$this->phraseLocales) {
            $this->initLocales();
        }

        $phraseCode = str_replace('_', '-', $locale);

        
/** * Sorts a definitions array. * * This sorts the definitions array first by the weight column, and then by * the plugin ID, ensuring a stable, deterministic, and testable ordering of * plugins. * * @param array $definitions * The definitions array to sort. */
  protected function sortDefinitions(array &$definitions) {
    array_multisort(array_column($definitions, 'weight'), SORT_ASC, SORT_NUMERIC, array_keys($definitions), SORT_ASC, SORT_NATURAL, $definitions);
  }

}
$required_dependency_graph = $dependency_graph;
    }
    $weights = [];
    foreach ($migrations as $migration_id => $migration) {
      // Populate a weights array to use with array_multisort() later.       $weights[] = $dependency_graph[$migration_id]['weight'];
      if (!empty($required_dependency_graph[$migration_id]['paths'])) {
        $migration->set('requirements', $required_dependency_graph[$migration_id]['paths']);
      }
    }
    // Sort weights, labels, and keys in the same order as each other.     array_multisort(
      // Use the numerical weight as the primary sort.       $weights, SORT_DESC, SORT_NUMERIC,
      // When migrations have the same weight, sort them alphabetically by ID.       array_keys($migrations), SORT_ASC, SORT_NATURAL,
      $migrations
    );

    return $migrations;
  }

  /** * Add one or more dependencies to a graph. * * @param array $graph * The graph so far, passed by reference. * @param int $id * The migration ID. * @param string $dependency * The dependency string. * @param array $dynamic_ids * The dynamic ID mapping. */
$data = array_merge($data$collector['timelineData']);
        }

        // Sort it         $sortArray = [
            array_column($data, 'start'), SORT_NUMERIC, SORT_ASC,
            array_column($data, 'duration'), SORT_NUMERIC, SORT_DESC,
            &$data,
        ];

        array_multisort(...$sortArray);

        // Add end time to each element         array_walk($datastatic function D&$row) {
            $row['end'] = $row['start'] + $row['duration'];
        });

        // Group it         $data = $this->structureTimelineData($data);

        return $data;
    }

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