Contents
PHP SPL Data structures
SplDoublyLinkedList Functions
add()
Description: Add a new value at the given index in the doubly linked list.
Example:
$list = new SplDoublyLinkedList();
$list->add(0, "A");
$list->add(1, "B");
print_r($list);
// Output: SplDoublyLinkedList Object ([0] => A [1] => B)
bottom()
Description: Peek the value of the node from the beginning of the doubly linked list.
Example:
$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");
echo $list->bottom();
// Output: A
count()
Description: Count the number of elements present in a doubly linked list.
Example:
$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");
echo $list->count();
// Output: 2
push()
Description: Push an element at the end of the doubly linked list.
Example:
$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");
print_r($list);
// Output: SplDoublyLinkedList Object ([0] => A [1] => B)
unshift()
Description: Add an element at the beginning of the doubly linked list.
Example:
$list = new SplDoublyLinkedList();
$list->push("B");
$list->unshift("A");
print_r($list);
// Output: SplDoublyLinkedList Object ([0] => A [1] => B)
top()
Description: Return the value of the last (top) node in a doubly-linked list.
Example:
$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");
echo $list->top();
// Output: B
pop()
Description: Pop the node from the end of the doubly linked list.
Example:
$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");
echo $list->pop();
// Output: B
isEmpty()
Description: Check whether the doubly linked list is empty.
Example:
$list = new SplDoublyLinkedList();
echo $list->isEmpty();
// Output: 1 (true)
rewind()
Description: Rewind the iterator back to the start or beginning of the doubly linked list.
Example:
$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");
$list->rewind();
echo $list->current();
// Output: A
shift()
Description: Remove the first element from the doubly linked list and return it.
Example:
$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");
echo $list->shift();
// Output: A
add()
Description: Add a new value at the given index in the doubly linked list.
Example:
$list = new SplDoublyLinkedList();
$list->add(0, "A");
$list->add(1, "B");
print_r($list);
// Output: SplDoublyLinkedList Object ([0] => A [1] => B)
bottom()
Description: Peek the value of the node from the beginning of the doubly linked list.
Example:
$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");
echo $list->bottom();
// Output: A
count()
Description: Count the number of elements present in a doubly linked list.
Example:
$list = new SplDoublyLinkedList();
$list->push("A");
$list->push("B");
echo $list->count();
// Output: 2
SplFixedArray Functions
count()
Description: Return the number of elements in the SplFixedArray.
Example:
$array = new SplFixedArray(5);
echo $array->count();
// Output: 5
current()
Description: Get the current entry of the array iterator.
Example:
$array = new SplFixedArray(3);
$array[0] = "A";
$array[1] = "B";
$array->rewind();
echo $array->current();
// Output: A
getSize()
Description: Get the size of the SplFixedArray.
Example:
$array = new SplFixedArray(4);
echo $array->getSize();
// Output: 4
key()
Description: Get the key of the current iterator index.
Example:
$array = new SplFixedArray(3);
$array[0] = "A";
$array->rewind();
echo $array->key();
// Output: 0
next()
Description: Move the iterator to the next entry.
Example:
$array = new SplFixedArray(3);
$array[0] = "A";
$array[1] = "B";
$array->rewind();
$array->next();
echo $array->current();
// Output: B
offsetExists()
Description: Check if the provided index exists in the SplFixedArray.
Example:
$array = new SplFixedArray(3);
echo $array->offsetExists(2);
// Output: 1 (true)
offsetGet()
Description: Get the value at the specified index in the SplFixedArray.
Example:
$array = new SplFixedArray(3);
$array[1] = "B";
echo $array->offsetGet(1);
// Output: B
offsetUnset()
Description: Unset the value of the specified index in the SplFixedArray.
Example:
$array = new SplFixedArray(3);
$array[1] = "B";
$array->offsetUnset(1);
print_r($array);
// Output: SplFixedArray Object ([0] => , [1] => , [2] => )
rewind()
Description: Rewind the array iterator back to the start.
Example:
$array = new SplFixedArray(3);
$array[0] = "A";
$array[1] = "B";
$array->next();
$array->rewind();
echo $array->current();
// Output: A
rewind()
Description: Rewind the array iterator back to the start.
Example:
$array = new SplFixedArray(3);
$array[0] = "A";
$array[1] = "B";
$array->next();
$array->rewind();
echo $array->current();
// Output: A
List of PHP SPL SplObjectStorage Functions
addAll()
Description: Add elements from another SplObjectStorage to the current one.
Example:
$storage1 = new SplObjectStorage();
$storage2 = new SplObjectStorage();
$obj1 = new stdClass();
$obj2 = new stdClass();
$obj3 = new stdClass();
$storage1->attach($obj1);
$storage2->attach($obj2);
$storage2->attach($obj3);
$storage1->addAll($storage2);
echo $storage1->count();
// Output: 3
attach()
Description: Add an object to the SplObjectStorage.
Example:
$storage = new SplObjectStorage();
$obj = new stdClass();
$storage->attach($obj);
echo $storage->count();
// Output: 1
contains()
Description: Check if a specific object exists in the SplObjectStorage.
Example:
$storage = new SplObjectStorage();
$obj = new stdClass();
$storage->attach($obj);
echo $storage->contains($obj);
// Output: 1 (true)
count()
Description: Get the number of objects in the SplObjectStorage.
Example:
$storage = new SplObjectStorage();
echo $storage->count();
// Output: 0
current()
Description: Get the current object in the iterator.
Example:
$storage = new SplObjectStorage();
$obj1 = new stdClass();
$obj2 = new stdClass();
$storage->attach($obj1);
$storage->attach($obj2);
$storage->rewind();
print_r($storage->current());
// Output: Object(stdClass)
detach()
Description: Remove a specific object from the SplObjectStorage.
Example:
$storage = new SplObjectStorage();
$obj = new stdClass();
$storage->attach($obj);
$storage->detach($obj);
echo $storage->count();
// Output: 0
getInfo()
Description: Retrieve the data associated with the current object.
Example:
$storage = new SplObjectStorage();
$obj = new stdClass();
$storage->attach($obj, "data");
echo $storage->getInfo();
// Output: data
key()
Description: Get the current iterator index.
Example:
$storage = new SplObjectStorage();
$obj1 = new stdClass();
$obj2 = new stdClass();
$storage->attach($obj1);
$storage->attach($obj2);
$storage->rewind();
echo $storage->key();
// Output: 0
next()
Description: Move the iterator to the next object.
Example:
$storage = new SplObjectStorage();
$obj1 = new stdClass();
$obj2 = new stdClass();
$storage->attach($obj1);
$storage->attach($obj2);
$storage->rewind();
$storage->next();
print_r($storage->current());
// Output: Object(stdClass)
offsetExists()
Description: Check if an object exists in the SplObjectStorage.
Example:
$storage = new SplObjectStorage();
$obj = new stdClass();
$storage->attach($obj);
echo $storage->offsetExists($obj);
// Output: 1 (true)
offsetGet()
Description: Retrieve the data associated with the specified object.
Example:
$storage = new SplObjectStorage();
$obj = new stdClass();
$storage->attach($obj, "info");
echo $storage->offsetGet($obj);
// Output: info
offsetSet()
Description: Set data for a specific object in the storage.
Example:
$storage = new SplObjectStorage();
$obj = new stdClass();
$storage->offsetSet($obj, "info");
echo $storage->getInfo();
// Output: info
offsetUnset()
Description: Unset a specific object from the storage.
Example:
$storage = new SplObjectStorage();
$obj = new stdClass();
$storage->attach($obj);
$storage->offsetUnset($obj);
echo $storage->count();
// Output: 0
List of PHP SPL SplObjectStorage Functions
__construct()
Description: Constructs a queue that is implemented using a doubly-linked list.
Example:
$queue = new SplQueue();
echo get_class($queue);
// Output: SplQueue
dequeue()
Description: Removes and returns the node from the front of the queue.
Example:
$queue = new SplQueue();
$queue->enqueue("First");
$queue->enqueue("Second");
echo $queue->dequeue();
// Output: First
enqueue()
Description: Adds an element to the back of the queue.
Example:
$queue = new SplQueue();
$queue->enqueue("First");
$queue->enqueue("Second");
echo $queue->bottom();
// Output: First
bottom()
Description: Returns the value of the node at the bottom (front) of the queue without removing it.
Example:
$queue = new SplQueue();
$queue->enqueue("First");
$queue->enqueue("Second");
echo $queue->bottom();
// Output: First