Home > Backend Development > PHP Tutorial > How to use list method in PHP

How to use list method in PHP

墨辰丷
Release: 2023-03-28 12:34:02
Original
1549 people have browsed it

This article mainly introduces the usage of the list method in PHP, and analyzes the relevant operating skills and precautions for assigning array values ​​​​to variables using the list method in the form of examples. Friends in need can refer to the following

for details As follows:

<?php
function small_numbers()
{
  return array (0, 1, 2);
}
list ($zero, $one, $two) = small_numbers();
var_dump($zero);
var_dump($one);
var_dump($two);
?>
Copy after login

Output:

int(0)
int(1)
int(2)
Copy after login
Copy after login

Change it

<?php
function small_numbers()
{
  return array (0, 1);
}
list ($zero, $one, $two) = small_numbers();
var_dump($zero);
var_dump($one);
var_dump($two);
?>
Copy after login

Output:

Notice: Undefined offset: 2 in D:\xampp\htdocs\t\test.php on line 6
int(0)
int(1)
NULL
Copy after login

Change it again

<?php
function small_numbers()
{
  return array (0, 1 ,2 ,3);
}
list ($zero, $one, $two) = small_numbers();
var_dump($zero);
var_dump($one);
var_dump($two);
?>
Copy after login

Output:

int(0)
int(1)
int(2)
Copy after login
Copy after login

Change it again and learn by drawing inferences

<?php
function small_numbers()
{
  return array (0, 1 , array(&#39;2&#39;));
}
list ($zero, $one, $two) = small_numbers();
var_dump($zero);
var_dump($one);
var_dump($two);
?>
Copy after login

Output:

int(0)
int(1)
array(1) {
[0]=>
string(1) "2"
}
Copy after login

The above is the entire content of this article, I hope it will be helpful to everyone's learning.


Related recommendations: Detailed explanation of the usage of str_pad() function in

php

Detailed explanation of bind_param() function usage in

php

phpMethod to implement PDO-based preprocessing

The above is the detailed content of How to use list method in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template