CKTIS / PHP
array_reverse()
Build an array in reverse iteration order without changing the original.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
array_reverse(array $array, bool $preserve_keys = false): arrayBuild an array in reverse iteration order without changing the original. String keys stay attached to their values; integer keys are renumbered unless key preservation is enabled. Enable it when chronological records use numeric identifiers that must survive reverse presentation.
Signature
array_reverse(array $array, bool $preserve_keys = false): array
Example output
[["B","A"],{"8":"B","4":"A"}]
Examples
<?php
$items = [4=>'A', 8=>'B'];
echo json_encode([array_reverse($items), array_reverse($items, true)]);
Result
[["B","A"],{"8":"B","4":"A"}]