PHP
There are several ways to assign the value of an array to a set of variables. It is more convenient to use theextract()
function, but forindex array
Language is more troublesome, so we can uselist
to solve this problem. This article will take you to take a look.
First, let’s take a look at the syntax oflist()
:
list ( mixed $var , mixed ...$vars = ? ) = $arr
$arr: Specify array
$var: a variable.
#$vars: More variables.
Return value: Return the specified array.
Code example:
1. List all variables in the array:
输出:coffee is brown and caffeine makes it special
2. Omit one variable in the array:
Copy after login
输出:coffee has caffeine.
3. Only the third variable in the array
Copy after login
输出:I need caffeine!
4.list() cannot work on strings
Copy after login
Recommendation:《2021 PHP interview questions summary (collection)》《php video tutorial》
The above is the detailed content of In-depth analysis of lists in PHP (with code examples). For more information, please follow other related articles on the PHP Chinese website!