list() function in PHP


The list() function assigns variables as if they were an array. It returns the assigned array.

Syntax

list(variable1, variable2, variable 3, ...)

Parameters

  • variable1 − the first variable

  • variable2 − more variables

  • variable3 − more variables

Return

The list() function returns the assigned array.

Example

The following is an example −

 Live Demo

<?php
$arr = array("David","Jack");
list($one, $two) = $arr;
echo "Selected candidates: $one and $two.";
?>

Output

The following is the output −

Selected candidates: David and Jack.

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 23-Dec-2019

30 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements