PHP: list() function
PHP: Assign variables as if they were an array
The list() function is used to assign values to a list of variables. Like array(), this is not really a function, but a language construct. list() is used to assign a list of variables in one operation.
Version:
(PHP 4 and above)
Syntax:
list(varname1, varname2.... varnamen )
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
varname1 | The first variable to be assigned | Required | Mixed* |
varname2..n | Next variable to be assigned | Optional | Mixed* |
*Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types.
Return value:
The assigned array.
Value Type: Array
Example:
<?php
$w3r1_array = array("php","javascript","asp");
list($x, $y, $z) = $w3r1_array;
echo "We have covered $x, $y and $z.";
$w3r2_array = array("php","javascript","asp");
list($x, , $z) = $w3r2_array;
echo "We have covered $x and $z and so many other topics";
?>
Output:
We have covered php, javascript and asp.We have covered php and asp and so many other topics
View the example in the browser
Practice here online :
See also
Previous: krsort
Next: natcasesort
PHP: Tips of the Day
PHP: How to generate a random, unique, alphanumeric string for use in a secret link?
Security Notice: This solution should not be used in situations where the quality of your randomness can affect the security of an application. In particular, rand() and uniqid() are not cryptographically secure random number generators. See Scott's answer for a secure alternative.
If you do not need it to be absolutely unique over time:
md5(uniqid(rand(), true))
Otherwise (given you have already determined a unique login for your user):
md5(uniqid($your_user_login, true))
Ref : https://bit.ly/31fd9wa
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook