WireArray is the base iterable array type used throughout the ProcessWire framework.

Nearly all collections of items in ProcessWire are derived from the WireArray type. This includes collections of pages, fields, templates, modules and more. As a result, the WireArray class is one you will be interacting with regularly in the ProcessWire API, whether you know it or not.

Below are all the public methods you can use to interact with WireArray types in ProcessWire. In addition to these methods, you can also treat WireArray types like regular PHP arrays, in that you can foreach() them and get or set elements using array syntax, i.e. $value = $items[$key]; to get an item or $items[] = $item; to add an item.


Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the WireArray class also inherits all the methods and properties of: Wire.

Traversal / Retrieval / Manipulation / Info / Output rendering / Other data storage / Changes / Fun tools / For hooks / Common

Traversal

Name Return Summary  
WireArray::and($item) WireArray Return a new copy of this WireArray with the given item(s) appended
WireArray::each() array, null, string or WireArray Perform an action upon each item in the WireArray
WireArray::first() Wire, mixed or bool Returns the first item in the WireArray or boolean false if empty.
Can also be used as property: WireArray::first
WireArray::getIterator() ArrayObject or Wire Allows iteration of the WireArray.
WireArray::last() Wire, mixed or bool Returns the last item in the WireArray or boolean false if empty.
Can also be used as property: WireArray::last

Retrieval

Name Return Summary  
WireArray::count() int Returns the number of items in this WireArray.
Can also be used as property: WireArray::count
WireArray::eq(int $num) Wire or null Returns the item at the given index starting from 0, or NULL if it doesn't exist.
WireArray::explode($property) array Return a plain array of the requested property from each item
WireArray::find($selector) WireArray Find all items in this WireArray that match the given selector.
WireArray::findOne($selector) Wire or bool Find a single item by selector
WireArray::findRandom(int $num) WireArray Find a specified quantity of random elements from this WireArray.
WireArray::findRandomTimed(int $num) WireArray Find a quantity of random elements from this WireArray based on a timed interval (or user provided seed).
WireArray::first() Wire, mixed or bool Returns the first item in the WireArray or boolean false if empty.
Can also be used as property: WireArray::first
WireArray::get($key) WireData, Page, mixed, array or null Returns the value of the item at the given index, or null if not set.
WireArray::getAll() $this Returns all items in the WireArray (for syntax convenience)
WireArray::getArray() array Get a PHP array of all the items in this WireArray with original keys maintained
WireArray::getKeys() array Returns a regular PHP array of all keys used in this WireArray.
WireArray::getNext(Wire $item) Wire or null Given an item, get the item that comes after it in the WireArray
WireArray::getPrev(Wire $item) Wire or null Given an item, get the item before it in the WireArray
WireArray::getProperty(string $property) Wire or mixed Get a predefined property of the array, or extra data that has been set.
WireArray::getRandom() WireArray, Wire, mixed or null Get a random item from this WireArray.
WireArray::getValues() array or Wire Returns a regular PHP array of all values used in this WireArray.
WireArray::has($key) bool Does this WireArray have the given item, index, or match the given selector?
WireArray::implode(string $delimiter) string Combine all elements into a delimiter-separated string containing the given property from each item
WireArray::index(int $num) WireArray Returns a new WireArray of the item at the given index.
WireArray::last() Wire, mixed or bool Returns the last item in the WireArray or boolean false if empty.
Can also be used as property: WireArray::last
WireArray::pop() Wire, mixed or null Pop an element off the end of the WireArray and return it
WireArray::reverse() WireArray Return a new reversed version of this WireArray.
WireArray::shift() Wire, mixed or null Shift an element off the beginning of the WireArray and return it
WireArray::slice(int $start) WireArray Get a slice of the WireArray.
WireArray::unique() WireArray Return a new array that is unique (no two of the same elements)

Manipulation

Name Return Summary  
WireArray::add($item) $this Add an item to the end of the WireArray.
WireArray::append($item) $this Append an item to the end of the WireArray
WireArray::filter($selector) $this Filter this WireArray to only include items that match the given selector (destructive)
WireArray::import($items) $this Import the given item(s) into this WireArray.
WireArray::insertAfter($item, $existingItem) $this Insert an item after an existing item
WireArray::insertBefore($item, $existingItem) $this Insert an item before an existing item
WireArray::not($selector) $this Filter this WireArray to only include items that DO NOT match the selector (destructive)
WireArray::pop() Wire, mixed or null Pop an element off the end of the WireArray and return it
WireArray::prepend($item) $this Prepend an item to the beginning of the WireArray.
WireArray::push($item) $this Push an item to the end of the WireArray.
WireArray::remove($key) $this Removes the given item or index from the WireArray (if it exists).
WireArray::removeAll() $this Removes all items from the WireArray, leaving it blank
WireArray::removeItems($items) $this Removes multiple identified items at once
WireArray::replace($itemA, $itemB) $this Replace one item with the other
WireArray::set($key, $value) $this Set an item by key in the WireArray.
WireArray::setArray($data) $this Like set() but accepts an array or WireArray to set multiple values at once
WireArray::shift() Wire, mixed or null Shift an element off the beginning of the WireArray and return it
WireArray::shuffle() $this Shuffle/randomize this WireArray
WireArray::sort($properties) $this Sort this WireArray by the given properties.
WireArray::unshift($item) $this Unshift an element to the beginning of the WireArray (alias for prepend)

Info

Name Return Summary  
WireArray::has($key) bool Does this WireArray have the given item, index, or match the given selector?
WireArray::isIdentical(WireArray $items) bool Is the given WireArray identical to this one?
WireArray::isValidItem(mixed $item) bool Is the given item valid for storange in this array?
WireArray::isValidKey($key) bool Is the given item key valid for use in this array?
WireArray::iterable(mixed $item) bool Determines if the given item iterable as an array.

Output rendering

Name Return Summary  
WireArray::each() array, null, string or WireArray Perform an action upon each item in the WireArray
WireArray::implode(string $delimiter) string Combine all elements into a delimiter-separated string containing the given property from each item

Other data storage

Name Return Summary  
WireArray::data() WireArray, mixed, array or null Store or retrieve an extra data value in this WireArray
WireArray::removeData(string $key) $this Remove a property/value previously set with the WireArray::data() method.

Changes

Name Return Summary  
WireArray::getItemsAdded() array or Wire Return array of all items added to this WireArray (while change tracking is enabled)
WireArray::getItemsRemoved() array or Wire Return array of all items removed from this WireArray (when change tracking is enabled)

Fun tools

Name Return Summary  
WireArray::and($item) WireArray Return a new copy of this WireArray with the given item(s) appended
WireArray::callUnknown(string $method, array $arguments) null or mixed Handler for when an unknown/unhooked method call is executed
WireArray::each() array, null, string or WireArray Perform an action upon each item in the WireArray
WireArray::explode($property) array Return a plain array of the requested property from each item
WireArray::implode(string $delimiter) string Combine all elements into a delimiter-separated string containing the given property from each item

For hooks

This methods are only useful for hooking and should not be called directly.

Name Return Summary  
WireArray::callUnknown(string $method, array $arguments) null or mixed Handler for when an unknown/unhooked method call is executed

Common

Name Return Summary  
WireArray::keys array All keys used in this WireArray
WireArray::setDuplicateChecking(bool $value) (nothing) Set the current duplicate checking state
WireArray::values array All values used in this WireArray

Additional methods and properties

In addition to the methods and properties above, WireArray also inherits the methods and properties of these classes: