Re: [PHP-DEV] clarify the destructuring list() concept
| Newsgroups | gmane.comp.php.general |
|---|---|
| Message-ID | <CACOt7mGiFc+wDen6bNbkJ6yrzUkFnMCf9KdQyKWKigMmkr_Cwg@mail.gmail.com> |
On Sat, 6 Jan 2024 at 18:02, Mönôme Epson <[email protected]> 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.