public function lists($value, $key = null)
{
$results = array();
foreach ($this->items as $item) {
// If the key is "null", we will just append the value to the array and keep
// looping. Otherwise we will key the array using the value of the key we
// received from the developer. Then we'll return the final array form.
if (is_null($key)) {
$results[] = $item->{$value};
} else {
$results[$item->{$key}] = $item->{$value};
}
}
return $results;
}
public function testLists() { $data = new Collection(array((object) array('name' => 'taylor', 'email' => 'foo'), (object) array('name' => 'dayle', 'email' => 'bar'))); $this->assertEquals(array('taylor' => 'foo', 'dayle' => 'bar'), $data->lists('email', 'name')); $this->assertEquals(array('foo', 'bar'), $data->lists('email')); }