WireArray::sort() method

Sort this WireArray by the given properties.

  • Sort properties can be given as a string in the format name, datestamp or as an array of strings, i.e. ["name", "datestamp"].

  • You may also specify the properties as property.subproperty, where property resolves to a Wire derived object in each item, and subproperty resolves to a property within that object.

  • Prepend or append a minus "-" to reverse the sort (per field).

Example

// Sort newest to oldest
$items->sort("-created");

// Sort by last_name then first_name
$items->sort("last_name, first_name"); 

Usage

// basic usage
$wireArray->sort($properties);

// usage with all arguments
$wireArray->sort($properties, $flags = null);

Arguments

NameType(s)Description
propertiesstring, array

Field names to sort by (CSV string or array).

flags (optional)int, null

Optionally specify sort flags (see sortFlags method for details).

Return value

$this

reference to current instance.


WireArray methods and properties

API reference based on ProcessWire core version 3.0.172

Twitter updates

  • ProcessWire 3.0.174 core updates: improvements to the new path/URL hooks and more— More
    12 March 2021
  • ProcessWire 3.0.173 adds several new requested features and this post focuses on one of my favorites: the ability to hook into and handle ProcessWire URLs, independent of pages— More
    5 March 2021
  • This week ProcessWire gained powerful new tools for finding pages and controlling how they are loaded. If you like to maximize performance and efficiency, you’ll like what 3.0.172 brings— More
    5 February 2021

Latest news

  • ProcessWire Weekly #356
    In the 356th issue of ProcessWire Weekly we'll cover the latest core updates (ProcessWire 3.0.173), introduce new third party modules RockCalculator and RockIframe, and take a closer look at a brand new site of the week. Read on!
    Weekly.pw / 6 March 2021
  • ProcessWire 3.0.173 core updates: New URL hooks
    ProcessWire 3.0.173 adds several new requested features and this post focuses on one of my favorites: the ability to hook into and handle ProcessWire URLs, independent of pages.
    Blog / 5 March 2021
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits