本文整理汇总了PHP中Collection::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::toArray方法的具体用法?PHP Collection::toArray怎么用?PHP Collection::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection::toArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMap
public function testMap()
{
$this->collection->map(function ($item) {
return sprintf('%s %s', $item['first_name'], $item['last_name']);
});
$this->assertEquals(['john smith', 'kara trace', 'phil mcKay', 'rose smith'], $this->collection->toArray());
}
示例2: getIncompleteProductLoads
public function getIncompleteProductLoads($user_id)
{
//get user and in progress product requests / ideas
$user = $this->eloquent->with(['ideas' => function ($query) {
$query->where('is_fulfilled', '=', 0);
}])->with(['productRequests' => function ($query) {
$query->whereNull('product_id');
}])->find($user_id);
if (empty($user)) {
return [];
}
$user = $user->toArray();
$product_requests = $user['product_requests'];
$ideas = $user['ideas'];
//compile inprogress items
$inprogress_items = new \Collection();
foreach ($product_requests as $product_request) {
$inprogress_items->add(['type' => 'id load', 'human_time_diff' => \Carbon::createFromFormat('Y-m-d H:i:s', $product_request['created_at'])->diffForHumans(), 'created_at' => $product_request['created_at'], 'updated_at' => $product_request['updated_at'], 'id' => $product_request['id'], 'description' => $product_request['vendor'] . ' ' . $product_request['vendor_id'], 'query' => ['vendor' => $product_request['vendor'], 'vendor_id' => $product_request['vendor_id']]]);
}
foreach ($ideas as $idea) {
$inprogress_items->add(['type' => 'idea load', 'human_time_diff' => \Carbon::createFromFormat('Y-m-d H:i:s', $idea['created_at'])->diffForHumans(), 'created_at' => $idea['created_at'], 'updated_at' => $idea['updated_at'], 'id' => $idea['id'], 'description' => $idea['description'], 'query' => ['idea_description' => $idea['description']]]);
}
$inprogress_items->sortBy('created_at');
return $inprogress_items->toArray();
}
示例3: fromCollection
public static function fromCollection(Collection $initialData)
{
$tree = new self();
foreach ($initialData->toArray() as $element) {
$tree->insert($element);
}
return $tree;
}
示例4: toArray
/**
* Provide a lossless cachable/storable array of the configuration of the
* ticket and it's timeline
*
* @return array
*/
public function toArray()
{
// We want to flatten certain values for quicker searching from store
$participants = array_map(function ($item) {
return $item->toArray();
}, $this->getParticipants());
$roles = [];
foreach ($this->getRoles() as $key => $role) {
$roles[$key] = array_map(function ($item) {
return $item->toArray();
}, array_values($role));
}
return ['id' => $this->id, 'status' => (string) $this->getStatus(), 'channel' => (string) $this->getChannel(), 'assigned_to' => (string) $this->getAssignedTo(), 'participants' => $participants, 'roles' => $roles, 'tags' => $this->getTags(), 'timeline' => $this->timeline->toArray()];
}
示例5: merge
/**
* @param array|Collection $data
* @return $this
*/
public function merge($data)
{
if ($data instanceof Collection) {
$this->_data = array_merge($this->_data, $data->toArray());
} else {
$this->_data = array_merge($this->_data, array_values($data));
}
$this->_clearIndexes();
return $this;
}
示例6: getAllBundles
/**
* @return array
*/
public function getAllBundles()
{
return array_merge($this->bundles->toArray(), $this->contributionBundles->toArray());
}
示例7: getResponses
public function getResponses()
{
return $this->responses->toArray();
}
示例8: merge
/**
* Adds elements from another collection
*
* @param Collection $col
*/
public function merge(Collection $col)
{
$this->elements = array_merge($this->elements, $col->toArray());
}
示例9: getCategories
public function getCategories()
{
return $this->categories->toArray();
}
示例10: PagerHelper
$collection->add('sixteen', 'diez y seis');
$collection->add('seventeen', 'diez y siete');
$collection->add('eighteen', 'diez y ocho');
$collection->add('ninetten', 'diez y nueve');
$collection->add('twenty', 'viente');
$collection->add('twenty one', 'viente uno');
$collection->add('twenty two', 'viente dos');
$collection->add('twenty three', 'viente tres');
$collection->add('twenty four', 'viente cuatro');
$collection->add('twenty five', 'viente cinco');
$collection->add('twenty six', 'viente seis');
$collection->add('twenty seven', 'viente siete');
$collection->add('twenty eight', 'viente ocho');
$collection->add('twenty nine', 'viente nueve');
$collection->add('thirty', 'treinte');
$datasource = new A_Pager_Array($collection->toArray());
// temporary hack until pager supports Collections
$pager = new A_Pager($datasource);
$pager->setPageSize(3);
// create a request processor to set pager from GET parameters
$request = new A_Pager_Request($pager);
$request->process();
$template = new A_Template_Include('templates/standard_pagination.tpl');
// create a HTML writer to output
#$helper = new A_Pager_HTMLWriter($pager);
// get rows of data
$start_row = $pager->getStartRow();
$end_row = $pager->getEndRow();
$rows = $datasource->getRows($start_row, $end_row);
$helper = new PagerHelper($pager, $template, 2);
?>
示例11: testToArray
public function testToArray()
{
$this->assertCount(4, $this->collection->toArray());
}
示例12: toArray
public function toArray()
{
$data = parent::toArray();
if (isset($this->id)) {
$data['id'] = $this->id;
}
return $data;
}
示例13: retainAll
/**
* @param Collection $elements
* @return boolean
*/
public function retainAll(Collection $elements)
{
$intersection = array_intersect($this->elements, (array) $elements->toArray());
$newElements = array_values($intersection);
$result = $newElements != $this->elements;
$this->elements = $newElements;
return $result;
}
示例14: fromCollection
/**
* Creates new collection using data from another collection
*
* @param \tjsd\collections\Collection $initialData collection providing data to be used
* @return \self collection filled with given data
*/
public static function fromCollection(Collection $initialData)
{
return new static($initialData->toArray());
}
示例15: toArray
/**
* {@inheritdoc}
*/
public function toArray()
{
$this->initialize();
return $this->coll->toArray();
}