Re: [php-src] Issue #11204: Improve syntax of creating associative array();
| From: | Erick de Azevedo Lima | Date: | Sun, 07 May 2023 12:38:03 +0000 |
| Subject: | Re: [php-src] Issue #11204: Improve syntax of creating associative array(); | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-244396@lists.php.net to get a copy of this message | ||
Hey, it's already possible with the function *\array_fill_keys*:
<?php
$array1 = \*array_fill_keys*(['key1', 'key2', 'key3',
'key4', 'key5',
'key6'], false);
\var_dump($array1);
https://3v4l.org/JBgrR
Simple, no repeats, and no language change. =)
Em dom., 7 de mai. de 2023 às 08:12, interduo <noreply@php.net> escreveu:
> Issue: https://github.com/php/php-src/issues/11204
> Author: interduo
>
> ### Description
>
> I see some cleaner way to declare associative arrays:
>
> This working code:
> ```
> $array1 = [
> 'key1' => false,
> 'key2 => false,
> 'key3' => false,
> 'key4' => false,
> 'key5' => false,
> 'key6' => false
> ];
> ```
>
> Could be like that (now it's not working in PHP):
> ```
> $array1 = [
> ('key1', 'key2', 'key3', 'key4', 'key5',
> 'key6') => false,
> ];
>
> print_r($array1);
>
> Array
> (
> [key1] =>
> [key2] =>
> [key3] =>
> [key4] =>
> [key5] =>
> [key6] =>
> )
> ```
>
> Simple and no repeats.
>