PHP Syntax list

 

- Info:

- list() is used to assign 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.

 

- 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);

?>