The list() function is an inbuilt function in PHP which is used to assign array values to multiple variables at a time. This function will only work on numerical arrays. When the array is assigned to multiple values, then the first element in the array is assigned to the first variable, second to the second variable and so on, till the number of variables. The number of variables cannot exceed the length of the numerical array.
Parameter: It accepts a list of variables separated by spaces. These variables are assigned values. The first variable is mandatory.
Return Value: The function returns the assigned array to the multiple variables passed. It does not assign a value to the $variableM if m>n, where n is the length of the array.
Below programs illustrate the list() function in PHP:
Program 1: Program to demonstrate the use of list() function.
a =1 b =2 c =3 a*b*c =6
Program 2: Program to demonstrate the runtime error of list() function.
PHP Notice: Undefined offset: 4 in /home/619f1441636b952bbd400f1e9e8e3d0c.php on line 6
- HTML | list Attribute
- CSS | list-style Property
- Bootstrap 4 | List Groups
- AngularJs | ng-list Directive
- Use of :even and :odd pseudo-classes with list items in CSS
- CSS | list-style-position Property
- CSS | list-style-type Property
- Create an unordered list without any bullets using CSS
- List group in bootstrap with examples
- HTML | <input> list Attribute
- CSS | list-style-image Property
- How to sort a list alphabetically using jQuery ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.