PHP list() Function

❮ 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.";
?>
Try it Yourself »

Definition and Usage

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

Note: Prior to PHP 7.1, this function only worked on numerical arrays.


Syntax

list(var1, var2, ...)

Parameter Values

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

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.";
?>
Try it Yourself »

❮ PHP Array Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.