(PHP 5 >= 5.3.0, PHP 7, PHP 8)
SplDoublyLinkedList::offsetSet —Sets the value at the specified $index to $value
Sets the value at the specifiedindex tovalue.
index The index being set. Ifnull, the next value will be added after the last item.
value The new value for theindex.
No value is returned.
ThrowsOutOfRangeException whenindex is out of bounds or whenindex cannot be parsed as an integer.
How to change elements of a SplDoublyLinkedList<?phpfunctionchange_elements($list,$old_index,$new_index){$tmp1=$list->offsetGet($old_index);$tmp2=$list->offsetGet($new_index);$list->offsetSet($old_index,$tmp2);$list->offsetSet($new_index,$tmp1);}$list=newSplDoublyLinkedList();$list->push("A");$list->push("B");$list->push("C");/*OUTPUTABC*/change_elements($list,0,1);/*OUTPUTBAC*/?>