Re: [PHP-DEV] clarify the destructuring list() concept

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On Sat, 6 Jan 2024 at 18:02, Mönôme Epson <glash.gnome@xxxxxxxxx> 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.

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux