List () Function in PHP 7

I have checked the php doc and it is written:

Warning
In PHP 5, list() assigns the values starting with the right-most parameter. In PHP 7, list() starts with the left-most parameter.

What do you mean by this term - list() starts with the left-most parameter.

Any example?

list() no longer assigns variables in reverse order

list() will now assign values to variables in the order they are defined, rather than reverse order. In general, this only affects the case where list() is being used in conjunction with the array operator, as shown below:

<?php
list($a[], $a[], $a[]) = [1, 2, 3];
var_dump($a);

Output of the above example in PHP 5:

array(3) {
  [0]=>
  int(3)
  [1]=>
  int(2)
  [2]=>
  int(1)
}

Output of the above example in PHP 7:

array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}

In general, it is recommended not to rely on the order in which list() assignments occur, as this is an implementation detail that may change again in the future.

Found in here: http://php.net/manual/en/migration70.incompatible.php

-TeNDoLLA

1 Like

This is good, now I don’t have to rely on reverse opposite order. Thanks for the link…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.