Collections with SPL
SPL Fixed Array
SplFixedArray stores values in numbered slots with a fixed size.
SPL Fixed Array
spl_fixed_array.php
<?php
$slot = ;
$items = new SplFixedArray(3);
$items[0] = "red";
$items[1] = "blue";
$items[2] = "green";
$chosen = $items[$slot];
$count = $items->count();
echo "slot=" . $slot . "\n";
echo "chosen=" . $chosen . "\n";
echo "count=" . $count . "\n";
<?php
$slot = ;
$items = new SplFixedArray(3);
$items[0] = "red";
$items[1] = "blue";
$items[2] = "green";
$chosen = $items[$slot];
$count = $items->count();
echo "slot=" . $slot . "\n";
echo "chosen=" . $chosen . "\n";
echo "count=" . $count . "\n";
<?php
$slot = ;
$items = new SplFixedArray(3);
$items[0] = "red";
$items[1] = "blue";
$items[2] = "green";
$chosen = $items[$slot];
$count = $items->count();
echo "slot=" . $slot . "\n";
echo "chosen=" . $chosen . "\n";
echo "count=" . $count . "\n";
fixed slots
Use a fixed array when the number of slots is known and each slot has a stable index.