PHP list

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP: list() function

PHP: Assign variables as if they were an array

The list() function is used to assign values to a list of variables. Like array(), this is not really a function, but a language construct. list() is used to assign a list of variables in one operation.

Version

(PHP 4 and above)

Syntax

list(varname1, varname2.... varnamen )

Parameters

Name

Description

Required /
Optional

Type

varname1

The first variable to be assigned

Required

Mixed*

varname2..n

Next variable to be assigned

Optional

Mixed*

*Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types.

Return value

The assigned array.

Value Type : Array

Pictorial Presentation :

php array list() function

Example :

  1. $w3r1_array = array("php","javascript","asp");  

  2. list($x, $y, $z) = $w3r1_array;  

  3. echo "We have covered $x,  $y and $z.";  

  4. $w3r2_array = array("php","javascript","asp");  

  5. list($x, , $z) = $w3r2_array;  

  6. echo "We have covered $x and $z and so many other topics";  

  7. ?>  

Output :

We have covered php, javascript and asp.We have covered php and asp and so many other topics