X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP list() Function

PHP Array Reference PHP Array Reference

Example

Assign variables as if they were an array:

<?php
$my_array = array("Dog","Cat","Horse");

list($a, $b, $c) = $my_array;
echo "I have several animals, a $a, a $b and a $c.";
?>

Run example »

Definition and Usage

The list() function is used to assign values to a list of variables in one operation.

Note: This function only works on numerical arrays.


Syntax

list(var1,var2...)

Parameter Description
var1 Required. The first variable to assign a value to
var2,... Optional. More variables to assign values to

Technical Details

Return Value: Returns the assigned array
PHP Version: 4+


More Examples

Example 1

Using the first and third variables:

<?php
$my_array = array("Dog","Cat","Horse");

list($a, , $c) = $my_array;
echo "Here I only use the $a and $c variables.";
?>

Run example »


PHP Array Reference PHP Array Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook