From 679f4d0368fc006c6f347bf44869507e3a7900d4 Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Wed, 19 Dec 2018 17:54:12 +0800 Subject: [PATCH] =?UTF-8?q?Collection=E5=A2=9E=E5=8A=A0values=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Collection.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/library/think/Collection.php b/library/think/Collection.php index 8e132b1b..f872476f 100644 --- a/library/think/Collection.php +++ b/library/think/Collection.php @@ -99,6 +99,16 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria return new static(array_keys($this->items)); } + /** + * 返回数组中所有的值组成的新 Collection 实例 + * @access public + * @return static + */ + public function values() + { + return new static(array_values($this->items)); + } + /** * 合并数组并返回一个新的 Collection 实例 * @access public @@ -273,7 +283,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria $result = []; foreach ($this->items as $row) { - $key = $value = null; + $key = $value = null; $keySet = $valueSet = false; if (null !== $indexKey && array_key_exists($indexKey, $row)) { @@ -309,7 +319,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria */ public function sort(callable $callback = null) { - $items = $this->items; + $items = $this->items; $callback = $callback ?: function ($a, $b) { return $a == $b ? 0 : (($a < $b) ? -1 : 1); };