PHP Syntax Statements Assignment list

 

- Info:

- list statement is used to assign values to a list of variables from non-asociative array in one operation.

- Like array(), this is not really a function, but a language construct.

- This tutorial is based on http://php.net/manual/en/function.list.php.

 

- Syntax:

- list(variable1, variable2, variable3) = array;

- list(variable1, , variable3) = array;

 

- Example:

- Create PHP Console Application Test.php.

 

Test.php

<?php

//DEFINE ARRAY.

$fruits = array("apple", "banana", "pear");

//LIST ALL VARIABLES.

list($apple, $banana, $pear) = $fruits;

print($apple."-".$banana."-".$pear."\n");

//SKIP VARIABLES.

list($apple, , $pear) = $fruits;

print($apple."-".$pear);

?>