Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Compact Array

An array is compact, or a packed array, if it only uses automated indices, starting with 0. This doesn’t really show in the written code, though performances are better for some operations.

Such array’s status may be reached by using array_values() or array_keys() on the array: such functions reindexes the values in the array.

This notion is not related to the compact() function.

<?php

    $array = [1,2,3];

    $notCompact = [1,2,3, 4=>4];

    $compactAgain = array_values($notCompact);

?>

Documentation

See Also