The Standard PHP Library (SPL) includes common data structures. The SPL groups
these structures by how they are implemented.
Here's an example that shows how to use the `SplDoublyLinkedList::offsetGet()`
function in PHP:
<?php // Declare an empty SplDoublyLinkedList $list = new \SplDoublyLinkedList; // Use SplDoublyLinkedList::add() function to // add elements to the SplDoublyLinkedList $list->add(0, 30); $list->add(1, 20); $list->add(2, 30); $list->add(3, "Geeks"); $list->add(4, 'G'); $list->rewind(); // Use SplDoublyLinkedList::offsetGet() function // to check index exist or not var_dump($list->offsetGet(2)); var_dump($list->offsetGet(3)); ?>
Output:
int(30) string(5) "Geeks"
Complete List of PHP SPL SplDoublyLinkedList Functions:
Doubly Linked List Functions | Description |
---|---|
add() | Add a new value at the specified index in the list. |
bottom() | Peek at the value of the first node (at the beginning) of the doubly linked list without removing it. |
count() | Count the number of elements present in the doubly linked list. |
current() | Return the value of the current element pointed to by the internal iterator. |
isEmpty() | Check whether the doubly linked list is empty (contains no elements). |
key() | Return the index (or key) of the current node pointed to by the internal iterator. |
next() | Move the internal iterator to the next node in the list. |
offsetExists() | Check whether a specific index exists in the doubly linked list. |
offsetGet() | Get the value at the specified index in the doubly linked list. |
offsetSet() | Set the value at the specified index in the doubly linked list. |
offsetUnset() | Unset (remove) the value at the specified index in the doubly linked list. |
pop() | Remove and return the value of the last node (at the end) of the doubly linked list. |
prev() | Move the internal iterator to the previous node in the list. |
push() | Add a new element to the end of the doubly linked list. |
rewind() | Reset the internal iterator to point to the first node (beginning) of the list. |
shift() | Remove and return the value of the first node (at the beginning) of the doubly linked list. |
top() | Return the value of the last node (at the end) of the doubly linked list without removing it. |
unshift() | Add a new element to the beginning of the doubly linked list. |
Complete List of PHP SPL SplObjectStorage Functions
SplObjectStorage Functions | Description |
---|---|
addAll() | Add all elements from another storage object to the current SplObjectStorage. |
attach() | Add an object to the SplObjectStorage. You can optionally associate data with the object. |
contains() | Check whether the storage contains a specific object. |
count() | Count the number of objects in the storage. |
current() | Get the value associated with the current iterator entry (the object itself). |
detach() | Remove an object from the SplObjectStorage. |
getInfo() | Get the data associated with the object pointed to by the current iterator. |
key() | Get the index (object) of the element pointed to by the current iterator. |
next() | Move the internal iterator to the next element in the storage. |
offsetExists() | Check whether a specific object exists in the storage. |
offsetGet() | Get the data associated with the object at the specified index. |
offsetSet() | **Not recommended:** While technically possible, setting an object at a specific index using offsetSet is not recommended for SplObjectStorage. It's better to use `attach()` with the desired object and data. |
offsetUnset() | Remove the object and its associated data from the storage at the specified index. |
removeAll() | Remove all objects from the current storage that are also contained in another storage. |
removeAllExcept() | Remove all objects from the current storage except for those that are also contained in another storage. |
rewind() | Reset the internal iterator to point to the first element (beginning) of the storage. |
serialize() | Serialize the SplObjectStorage object to a string representation. |
setInfo() | Set the data associated with the current iterator entry (the object itself). |
unserialize() | Unserialize a SplObjectStorage object from a previously serialized string. |
valid() | Check whether the current iterator is pointing to a valid element in the storage (i.e., not "past the end"). |
Complete List of PHP SPL SplQueue Functions:
Queue Functions | Description |
---|---|
__construct() | Optional: Initializes a queue object. In some implementations, a queue can be created without explicitly calling a constructor. |
dequeue() | Remove and return the element from the front (beginning) of the queue. If the queue is empty, it may return an error or null value. |
enqueue() | Add a new element to the back (end) of the queue. |