PHP Array list() Function

What is list() Function?

Explanation

The "list()" function assigns variables as if they were in an array.

Syntax:


list(var1,var2...)

In the above syntax "var1" is the first variable to be assigned and can have any number of variables.

Example :


<?php
$myarray=array("Grapes","Apple","Cherry");
list($a,$b,$c)= $myarray;
echo "I have several fruits $a, $b, $c";
?>
Result :

I have several fruits Grapes, Apple, Cherry

In the above example the variables "$a,$b,$c" is assigned the values of the array "$myarray".

PHP Topics


Ask Questions

Ask Question