Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.
Anahkiasen edited this page Dec 19, 2012 · 12 revisions

Available methods


Informations about an object

Object::keys(object)

Get the keys from an object

Object::values(object)

Get the values from an object

Object::methods(object)

List all methods of an object


Alter an object

Object::set(array, key, value)

Set an value in an array using dot notation

$object = new stdClass;
Object::set($object, 'foo.bar', 'bis') // $object->foo['bar'] = 'bis'

Object::pluck(object, column)

Pluck a column from an array of objects

Object::pluck($articles, 'title'); // Returns array('title1', 'title2', ...)

Object::remove(array, key)

Remove attributes from objects using dot notation

Object::remove($articles, '1.author.name') // Will unset $articles[1]->author->name

Object::group(object, grouper)

Group an array by the results of a closure Instead of a closure a property name can be passed to group by it

Object::group($articles, function($value) {
  return $articles->created_at->format('Y'); // Returns articles sorted by creation year
})

Object::sort(object, [sorter], [direction])

Sort an array The second argument can be a closure returning what to sort by, or a property name The third argument is the direction (asc or desc)

Object::sort($articles, function($article) {
  return $article->name; // Returns article sorted by name
});
Object::sort($articles, 'author.name', 'desc') // Returns articles sorted by author name, DESC

Object::unpack(object)

Unpack an object's attribute (similar to doing object = object->something) but without having to know which key to fetch

$object = (object) array('attributes' => array('name' => 'foo', 'age' => 18))
$attributes = Object::unpack($object)