Php list
From w3cyberlearnings
Contents |
PHP function list
This function assigns values to a list of variables.
Syntax list
- v1: variable 1
- v2: variable 2
- v3: variable 3
list(v1, v2, v3...) = array;
Example 1
<?php list($name, $score, $team) = array('Bob', 30, 'Team 1'); echo "Name: $name<br/>"; echo "Score: $score<br/>"; echo "Team: $team<br/>"; ?>
Output
Name: Bob Score: 30 Team: Team 1
Example 2
<?php $name_score = array( 'Ella' => 30, 'Amelia' => 2, 'Liam' => 21 ); while (list($name, $score) = each($name_score)) { echo $name . ' scores ' . $score . '<br/>'; } ?>
Output
Ella scores 30 Amelia scores 2 Liam scores 21
Related Links
- array_change_key_case
- array_chunk
- array_combine
- array_count_values
- array_diff_assoc
- array_diff_key
- array_diff_uassoc
- array_diff_ukey
- array_diff
- array_fill_keys
- array_fill
- array_filter
- array_flip
- array_intersect_assoc
- array_intersect_key
- array_intersect_uassoc
- array_intersect_ukey
- array_intersect
- array_key_ exists
- array_keys