PHP list()Functions

PHP Array ReferenceComplete PHP Array Reference

Examples

Assign values from an array to some variables:

<?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 group of variables in one operation.

Note:This function only works for numerically indexed arrays.


Syntax

list(var1,var2...)

Parameters Description
var1 Required. The first variable to assign.
var2,... Optional. More variables to assign.

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 ReferenceComplete PHP Array Reference Other Extensions