W3Schools.com

PHP list() Function


PHP Array Reference Complete PHP Array Reference

Definition and Usage

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

Syntax

list(var1,var2...)

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


Tips and Notes

Note: This function only works on numerical arrays.


Example 1

<?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.";
?>

The output of the code above will be:

I have several animals, a Dog, a Cat and a Horse.


Example 2

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

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

The output of the code above will be:

Here I only use the Dog and Horse variables.


PHP Array Reference Complete PHP Array Reference
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE