How to use list in PHP

In this article, I will explain how the list() function can be used in PHP.
  • 1767

list() function in PHP

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

  • The list() function only works on numerical arrays.

  • The list() function can be hold multiple values.

Syntax

list(val1,val2)

Parameter

  • val1 val1 is required parameter. the first variable assign to val1.
  • val2 val2 is optional parameter. the second variable assign to val2 .

Example

The following example show to how the list() function can be used in PHP.

<html>

<body>

<h3 style="color: blueviolet;">list() function example in PHP</h3>

    <?php

    $array_demo = array("Welcome","to","C-sharpcorner");

    list($a, $b, $c) = $array_demo;

    echo " $a $b $c..";

    ?>

</body>

</html>

 

Output

listphp.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.