Jump to: navigation, search

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


Navigation
Web
SQL
MISC
References