From 2238de7a9fc3715356211d80212e77064fb364ca Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 13 Oct 2017 16:29:57 +0800 Subject: [PATCH] =?UTF-8?q?Collection=E7=B1=BB=E5=A2=9E=E5=8A=A0push?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Collection.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/library/think/Collection.php b/library/think/Collection.php index d88c3183..3fcba5cd 100644 --- a/library/think/Collection.php +++ b/library/think/Collection.php @@ -167,9 +167,9 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria /** * 在数组开头插入一个元素 - * @param mixed $value - * @param null $key - * @return int + * @param mixed $value + * @param miexed $key + * @return void */ public function unshift($value, $key = null) { @@ -180,6 +180,21 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria } } + /** + * 在数组结尾插入一个元素 + * @param mixed $value + * @param mixed $key + * @return void + */ + public function push($value, $key = null) + { + if (is_null($key)) { + $this->items[] = $value; + } else { + $this->items[$key] = $value; + } + } + /** * 给每个元素执行个回调 *