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

Unpack Arrays In Arrays

The ellipsis operator can now be used in arrays, with an effect similar to array_merge(). In particular, the string keys are now supported.

PHP code

<?php

$array = [...['a' => 'foo'], ...['b' => 'bar']];

print_r($array);

?>

Before

PHP Fatal error:  Cannot unpack array with string keys

Fatal error: Cannot unpack array with string keys

After

Array
(
    [a] => foo
    [b] => bar
)

PHP version change

This behavior changed in 8.1.

Error Messages

Extension

Analyzer

© 2023-2026, Damien Seguy - Exakat