PHP 8.5.0 Alpha 2 available for testing

Voting

: min(five, nine)?
(Example: nine)

The Note You're Voting On

Premysl Karbula
2 years ago
A function which replaces some portion od doubly linked list (DLL) with items from specified array.

<?php

/**
* Replace some portion (specified by index and length) of DLL with items
* from the specified replacement array.
*/
public function dll_splice(
\SplDoublyLinkedList $dll,
int $start,
int $length,
array
$replacement,
):
void {

if (
$start < 0 || ($start + $length) > $dll->count()) {
throw new
\OutOfRangeException("Invalid range for splicing");
}

for (
$i = 0; $i < $length; $i++) {
$dll->offsetUnset($start);
}

foreach (
$replacement as $item) {
$dll->add($start, $item);
}

}

?>

<< Back to user notes page

To Top