Home > Backend Development > PHP8 > body text

A big explanation of the new features of PHP8.1: Unpacking arrays using string keys

藏色散人
Release: 2023-02-17 12:18:01
Original
2625 people have browsed it

This article is a translation, original address: https://stitcher.io/blog/new-in-php-81#array-unpacking-with-string-keys-rfc

A big explanation of the new features of PHP8.1: Unpacking arrays using string keys

Array unpacking with string keys

Array unpacking is already allowed in PHP 7.4, but it only works with number key. The reason string keys were not supported before was because there was no consensus on how to merge array duplicates.

RFC cleanly solves this problem by following the following semantics array_merge:

$array1 = ["a" => 1];
$array2 = ["b" => 2];
$array = ["a" => 0, ...$array1, ...$array2];
var_dump($array); // ["a" => 1, "b" => 2]
Copy after login

See RFC for details: https://wiki.php.net/rfc /array_unpacking_string_keys

The above is the detailed content of A big explanation of the new features of PHP8.1: Unpacking arrays using string keys. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template