w3resource logo


PHP list function

PHP : list() function

<<PreviousNext>>

Description

The list() function is used to assign values to a list of variables as if they were an array.

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 :

<?php
$w3r1_array = array("php","javascript","asp");
list($x, $y, $z) = $w3r1_array;
echo "We have covered $x,  $y and $z.";
$w3r2_array = array("php","javascript","asp");
list($x, , $z) = $w3r2_array;
echo "We have covered $x and $z and so many other topics";
?>

Output :

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

View the example in the browser

See also

PHP Function Reference

<<PreviousNext>>

Rate this tutorial


Your Rating: not set

Share this tutorial

RSS Feed