src/Support/Collection/StringSet.php
/**
     * Inserts an item before another item in the set.
     */
Inserts an item before another item in the set.
Inserts an item before another item in the set .
public function insertBefore(string $item, string $newItem): void
    {
        if (!isset($this->cache[$item])) {
            return;
        }
        if (isset($this->cache[$newItem])) {
            return;
        }
        $this->cache[$newItem] = true;
        ++$this->length;
        if ($this->list[0] === $item) {
            array_unshift($this->list, $newItem);
            return;
        }
        $index = array_search($item, $this->list, true);
        array_splice($this->list, $index, 0, [$newItem]);
    }
public function insertBefore ( string $ item , string $ newItem ) : void { if ( ! isset ( $ this -> cache [ $ item ] ) ) { return ; } if ( isset ( $ this -> cache [ $ newItem ] ) ) { return ; } $ this -> cache [ $ newItem ] = true ; ++ $ this -> length ; if ( $ this -> list [ 0 ] === $ item ) { array_unshift ( $ this -> list , $ newItem ) ; return ; } $ index = array_search ( $ item , $ this -> list , true ) ; array_splice ( $ this -> list , $ index , 0 , [ $ newItem ] ) ; }
Inserts an item before another item in the set.
Inserts an item before another item in the set .
// If we are trying to insert before the first item in the array use // array_unshift instead of searching the array and then splicing the // value in as unshifting is faster.