PageArray/WireArray


Getting Items

$a->explode($key)

Introduced in Version 2.4

Description

Return a plain array of the requested key/property from each item. Similar to PHP's explode() function.

The returned PHP array uses the same keys as the original WireArray. 

$array = $items->explode($property);

$property
The name of the property (string) to have in each array element (i.e. "title"). You may also provide a function/closure here that should return the value to store. When a function/closure is used it receives the $item as the first argument and the $key (if needed) as the second. 

Examples

// get an array containing the 'title' of each page
$array = $items->explode('title'); 

// get an array containing the id, url and title of each page
$array = $items->explode(function($item) {
  return array(
    'id' => $item->id, 
    'url' => $item->url, 
    'title' => $item->title
  ); 
});


Post Comment