PHP list method usage example, phplist usage example
This example describes the usage of the list Method in PHP. We will share this with you for your reference. The details are as follows:
<?phpfunction small_numbers(){ return array (0, 1, 2);}list ($zero, $one, $two) = small_numbers();var_dump($zero);var_dump($one);var_dump($two);?>
Output:
int(0)int(1)int(2)
Change
<?phpfunction small_numbers(){ return array (0, 1);}list ($zero, $one, $two) = small_numbers();var_dump($zero);var_dump($one);var_dump($two);?>
Output:
Notice: Undefined offset: 2 in D:\xampp\htdocs\t\test.php on line 6int(0)int(1)NULL
Change it.
<?phpfunction small_numbers(){ return array (0, 1 ,2 ,3);}list ($zero, $one, $two) = small_numbers();var_dump($zero);var_dump($one);var_dump($two);?>
Output:
int(0)int(1)int(2)
Let's change the learning method.
<?phpfunction small_numbers(){ return array (0, 1 , array('2'));}list ($zero, $one, $two) = small_numbers();var_dump($zero);var_dump($one);var_dump($two);?>
Output:
int(0)int(1)array(1) {[0]=>string(1) "2"}