Data Structure

A data structure is a way of organizing and storing data in memory to enable efficient access and modification. PHP’s primary data structure are the classes and arrays, which include indexed arrays, associative arrays, anonymous classes and nested structures in a single construct.

For more specialized needs, the spl and ds extensions offers types beyond the default PHP ones.

Choosing the right data structure has a direct impact on algorithmic complexity and memory usage.

<?php

    use Ds\Vector;
    use Ds\Map;

    $vector = new Vector([1, 2, 3]);
    $map    = new Map(['key' => 'value']);

    $stack = new SplStack();
    $stack->push('first');

?>

Documentation

See also Data Structures for PHP (ds extension) and SPL Data Structures.

Related : Array, Data Structure, Standard PHP Library (SPL), Collection, Deque, SplStack, Map, Tree, Queue, Algorithmic Complexity, Big-o-notation, Bucket, Handle, Pair, Pop, Sequence, Set, SplDoublyLinkedList, SplObjectStorage

Related packages : php-ds/php-ds