Re: clarify the destructuring list() concept
| From: | gordonisnz at gmail dot com | Date: | Sat, 06 Jan 2024 05:32:13 +0000 |
| Subject: | Re: clarify the destructuring list() concept | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-328352@lists.php.net to get a copy of this message | ||
On Sat, 6 Jan 2024 at 18:02, Mönôme Epson <glash.gnome@gmail.com> wrote:
>
>
> ---------- Forwarded message ---------
>
> For example :
> $key = "a";
> $value = 1;
> $array = [$key => $value];
>
> [$key => $value] = $array;
>
> We all agree that now $key = 'a' and $value = 1
>
> And I wonder why
> What happens in this case :
>
> [$key => $value] = ['b'=>2];
>
> $key = 'b' and $value = 2 or all is null ?
>
My question is: I see list() as the reciprocal of an array(). Do you think
> it would be interesting for everyone if I proposed my vision?
>
>
How will this help us?
In your example above, You want [ $key => $value ] to equal b and 2
Why not just say $key="b"; $value=2; ? Why the complex array or involve
the array at all?
or just say $array["b"]=2; much simpler - if you wanted it in the array.
--
Gordon.