array_splice

Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Remove a portion of the array and replace it with something else
<?php array_splice(    array &$array,    int $offset,    ?int $length = null,    mixed $replacement = []): array
<?php     public function splice($offset, $length = null, $replacement = [])

    {

        if (func_num_args() === 1) {

            return new static(array_splice($this->items, $offset));

        }



        return new static(array_splice($this->items, $offset, $length, $this->getArrayableItems($replacement)));
<?php             return new static(array_splice($this->items, $offset));

        }



        return new static(array_splice($this->items, $offset, $length, $this->getArrayableItems($replacement)));

    }
<?php     {

        $row = array_values(Arr::except($failed, ['payload', 'exception']));



        array_splice($row, 3, 0, $this->extractJobName($failed['payload']) ?: '');



        return $row;

    }
<?php     protected function spliceIntoParameters(array &$parameters, $offset, $value)

    {

        array_splice(

            $parameters, $offset, 0, [$value]

        );

    }

}
<?php     protected function moveMiddleware($middlewares, $from, $to)

    {

        array_splice($middlewares, $to, 0, $middlewares[$from]);



        unset($middlewares[$from + 1]);
<?php     public static function findPackagesForClassName(string $className): array

    {

        $parts = explode('\\', $className);

        $queryParts = array_splice($parts, 0, 2);



        $url = 'https://packagist.org/search.json?q='.implode(' ', $queryParts);
<?php         $injectIndex = array_search($before, $bootstrappers, true);



        if ($injectIndex !== false) {

            array_splice($bootstrappers, $injectIndex, 0, [$inject]);

        }



        return $bootstrappers;
<?php             $cache->delete($cachePath);

        }



        return $size ? array_splice($size, 0, 2) : [0, 0];

    }
<?php         $realpath = Storage::disk('test')->getAdapter()->getPathPrefix().'path/to/asset.jpg';

        $this->assertFileExists($realpath);

        $imagesize = getimagesize($realpath);

        $this->assertEquals([30, 60], array_splice($imagesize, 0, 2));



        $dimensions = $this->dimensions->asset($asset);
<?php     public function removeInstaller(InstallerInterface $installer)

    {

        if (false !== ($key = array_search($installer, $this->installers, true))) {

            array_splice($this->installers, $key, 1);

            $this->cache = array();

        }

    }
<?php         foreach ($this->getPackages() as $key => $repoPackage) {

            if ($packageId === $repoPackage->getUniqueName()) {

                array_splice($this->packages, $key, 1);




                $this->packageMap = null;
<?php         if (\count($values) < \count($params)) {

            $params = \array_slice($params, 0, \count($values));

        } elseif (\count($values) > \count($params)) {

            $values[] = new EnumStub(array_splice($values, \count($params)), false);

            $params[] = $variadic;

        }

        if (['...'] === $params) {
<?php             $line = $import->getStartLine();

        }



        array_splice($lines, $line - 1, 0, 'use Illuminate\\Database\\Eloquent\\Factories\\HasFactory;');



        $traits = $class->getTraitUses();

        if (empty($traits)) {
<?php                 ++$line; // advance one more line to place the trait...

            }



            array_splice($lines, $line, 0, '    use HasFactory;' . PHP_EOL);

        } else {

            $line = $traits[0]->getStartLine();

            array_splice($lines, $line + 1, 0, '    use HasFactory;');
<?php             array_splice($lines, $line, 0, '    use HasFactory;' . PHP_EOL);

        } else {

            $line = $traits[0]->getStartLine();

            array_splice($lines, $line + 1, 0, '    use HasFactory;');

        }



        File::put($path, implode(PHP_EOL, $lines));