CKTIS / PHP
array_splice()
Sostituisce un segmento per posizione nell’array stesso e restituisce gli elementi rimossi.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
array_splice(array &$array, int $offset, ?int $length = null, mixed $replacement = []): arraySostituisce un segmento per posizione nell’array stesso e restituisce gli elementi rimossi. Il sostituto può avere un’altra lunghezza. Una lunghezza 0 inserisce soltanto. Le chiavi intere vengono rinumerate e quelle del sostituto vengono ignorate.
Firma
array_splice(array &$array, int $offset, ?int $length = null, mixed $replacement = []): array
Output dell’esempio
[["B"],["A","X","Y","C"]]
Esempi
<?php
$queue = ['A','B','C'];
$removed = array_splice($queue, 1, 1, ['X','Y']);
echo json_encode([$removed, $queue]);
Risultato
[["B"],["A","X","Y","C"]]