WireArray::data() method

Store or retrieve an extra data value in this WireArray

The data() function is exactly the same thing that it is in jQuery: http://api.jquery.com/data/.

Example

// set a data value named 'foo' to value 'bar'
$a->data('foo', 'bar');

// retrieve the previously set data value
$bar = $a->data('foo');

// get all previously set data
$all = $a->data(); 

Usage

// basic usage
$items = $wireArray->data();

// usage with all arguments
$items = $wireArray->data($key = null, $value = null);

Arguments

NameType(s)Description
key (optional)string, null, array, bool

Name of data property you want to get or set, or:

  • Omit to get all data properties.
  • Specify associative array of [property => value] to set multiple properties.
  • Specify associative array and boolean TRUE for $value argument to replace all data with the new array given in $key.
  • Specify regular array of property names to return multiple properties.
  • Specify boolean FALSE to unset property name specified in $value argument.
value (optional)mixed, null, bool

Value of data property you want to set. Omit when getting properties.

  • Specify boolean TRUE to replace all data with associative array of data given in $key argument.

Return value

WireArray mixed array null

Returns one of the following, depending on specified arguments:

  • mixed when getting a single property: whatever you set is what you will get back.
  • null if the property you are trying to get does not exist in the data.
  • $this reference to this WireArray if you were setting a value.
  • array of all data if you specified no arguments or requested multiple keys.

See Also


WireArray methods and properties

API reference based on ProcessWire core version 3.0.214

Twitter updates

    Error retrieving Twitter status

Latest news

  • ProcessWire Weekly #473
    In the 473rd issue of ProcessWire Weekly we'll check out latest core updates, introduce new third party module called Template Fragment Controller, and more. Read on!
    Weekly.pw / 3 June 2023
  • A look at the new Page Edit Restore module
    The new Page Edit Restore module helps to prevent page edits in the admin from getting lost when the user’s session is lost. This post covers it in detail.
    Blog / 12 May 2023
  • Subscribe to weekly ProcessWire news

“Indeed, if ProcessWire can be considered as a CMS in its own right, it also offers all the advantages of a CMF (Content Management Framework). Unlike other solutions, the programmer is not forced to follow the proposed model and can integrate his/her ways of doing things.” —Guy Verville, Spiria Digital Inc.