Laravel Collection 格式化登机口
打赏作者

JellyBool

为啥别人都会出现两个重复的评论

George

这个叼………………

liudong0763

这个叼………………

lurrpis

为啥别人都会出现两个重复的评论

chenze007

vendor\laravel\framework\src\Illuminate\Support\Collection.php

/**
* Push an item onto the end of the collection.
*
* @param mixed $value
* @param mixed $key
* @return this/publicfunctionpush(this */ public function push(value, $key = null)
{
this>offsetSet(this->offsetSet(key, $value);

    return $this;
}

里面的 push 少了一个$key 的参数 应该是作者遗漏的 能jelly 能通知官方一下 么

JellyBool 回复 chenze007

没看懂什么意思

chenze007 回复 JellyBool

vendor\laravel\framework\src\Illuminate\Support\Collection.php
jelly你打开这个文件 看一下push方法就 知道了

JellyBool 回复 chenze007

5.1 和 5.3 是这样:

 /**
     * Push an item onto the end of the collection.
     *
     * @param  mixed  $value
     * @return $this
     */
    public function push($value)
    {
        $this->offsetSet(null, $value);

        return $this;
    }

貌似没有什么不妥吧

chenze007 回复 JellyBool

这里应该 有 $key 可以指定他的键值
/**
* Push an item onto the end of the collection.
*
* @param mixed $value
* @param mixed $key
* @return this/publicfunctionpush(this */ public function push(value, $key = null)
{
this>offsetSet(this->offsetSet(key, $value);

    return $this;
}
JellyBool 回复 chenze007

这是作者的考虑吧,你可以使用 put :

  /**
     * Put an item in the collection by key.
     *
     * @param  mixed  $key
     * @param  mixed  $value
     * @return $this
     */
    public function put($key, $value)
    {
        $this->offsetSet($key, $value);

        return $this;
    }
chenze007 回复 JellyBool

谢了 jelly 看来 老司机早已看透了一切