Open In App
Related Articles

PHP SPL Data structures Complete Reference

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Standard PHP Library (SPL) the collection of standard data structures. The SPL data structure grouped the contents according to their implementation.

Example: Below programs illustrate the SplDoublyLinkedList::offsetGet() function in PHP:

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:

Functions

Description

Example

add()Add a new value at the given index.
Try
bottom()Peek the value of the node from the beginning of the doubly linked list.
Try
count()Count the number of elements present in a doubly linked list.
Try
current()Return the current element of the array.
Try
isEmpty()Check whether the doubly linked list is empty or not.
Try
key()Return the index of the current node.
Try
next()Move the index into next index.
Try
offsetExists()Check whether the given index exists or not.
Try
offsetGet()Returns the value at the given index.
Try
offsetSet()Set the value at the given index.
Try
offsetUnset()That is used to unset the value at the given index.
Try
pop()pop the node from the end of the doubly linked list.
Try
prev()Move to the previous entry.
Try
push()Push an element at the end of the doubly linked list.
Try
rewind()Rewind the iterator back to the start or beginning.
Try
shift()Shift the node from the beginning of the doubly linked list.
Try
top()Return the value of the last (top) node in a doubly-linked list.
Try
unshift()Add the element at the beginning of a doubly linked list.
Try

Complete List of PHP SPL SplFixedArray Functions

Functions

Description

Example

count()Return the size of the array.
Try
current()Get the current entry of the array.
Try
getSize()Get the size of the array.
Try
key()Get the key of the current index of the array.
Try
next()Move the array element to the next entry of the array.
Try
offsetExists()Check provided index exist or not in an array.
Try
offsetGet()Get the offset of the specified index in an array.
Try
offsetUnset()Unset the value of the requested index.
Try
rewind()Rewind the array iterator to the start position.
Try
setSize()Set the size of the array.
Try
toArray()Get a PHP array from the fixed array.
Try
valid()Check the array can contain more elements or not.
Try

Complete List of PHP SPL SplObjectStorage Functions

 Functions

Description

Example

addAll()Add elements from another storage.
Try
attach()Add objects into the SplObjectStorage.
Try
contains()Check whether the storage object contains a specified object or not.
Try
count()Count the number of objects in storage.
Try
current()Get the current entry of storage.
Try
detach()Remove objects from the storage.
Try
getinfo()Get the data associated with the object by the current
Try
key()Get the index of the currently pointing iterator.
Try
next()Move to the next entry of storage. 
Try
offsetExists()Check the object exists in storage or not.
Try
offsetGet()Get the data associated with the object.
Try
offsetSet()Set the object of storage.
Try
offsetUnset()Set the object from the storage.
Try
removeAll()Remove all objects contained in another storage from the current storage.
Try
removeAllExcept()Remove all objects from storage except for those contains in another storage.
Try
rewind()Rewind the iterator to the first storage element.
Try
serialize()Serialize the result of the storage
Try
setInfo()Set the data associated with the current iterator entry.
Try
unserialize()Unserialize the storage from its serialize string
Try
valid()Check the current storage entry is valid or not.
Try

Complete List of PHP SPL SplQueue Functions:

Functions

Description

Example

__construct()Construct a queue that is implemented using a doubly-linked list.
Try
dequeue()Dequeue the node from the queue.
Try
enqueue()Add the element to the queue.
Try


Last Updated : 23 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads