Example 1 — Remove an Item
Remove the second color from a list.
<?php
$colors = ["red", "green", "blue"];
$removed = array_splice($colors, 1, 1);
echo "Removed: ", implode(", ", $removed), PHP_EOL;
echo "Left: ", implode(", ", $colors), PHP_EOL; How It Works
- Create a list with three colors.
- Offset 1 and length 1 mean: remove one item starting at position 1.
- The removed item ("green") is returned in a new array.
- The original array now holds only "red" and "blue".

