★ wanayoo — archive 1999 http://www.php.net/manual/function.list.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Arrays
Quick Reference
Arrays
* array
* array_count_values
* array_flip
* array_keys
* array_merge
* array_pad
* array_pop
* array_push
* array_reverse
* array_shift
* array_slice
* array_splice
* array_unshift
* array_values
* array_walk
* arsort
* asort
* compact
* count
* current
* each
* end
* extract
* in_array
* key
* krsort
* ksort
* list
* next
* pos
* prev
* range
* reset
* rsort
* shuffle
* sizeof
* sort
* uasort
* uksort
* usort
Manual: list
View the source code for this pageSearch the site



Previous page
 ksort
next 
Next page


list

list -- Assign variables as if they were an array

Description

void list(...);

Like array(), this is not really a function, but a language construct. list() is used to assign a list of variables in one operation.

Example 1. list() example

  1 
  2 <table>
  3  <tr>
  4   <th>Employee name</th>
  5   <th>Salary</th>
  6  </tr>
  7 
  8 <?php
  9 
 10 $result = mysql($conn, "SELECT id, name, salary FROM employees");
 11 while (list($id, $name, $salary) = mysql_fetch_row($result)) {
 12     print(" <tr>\n".
 13           "  <td><a href=/old?u=http%3A%2F%2Fwww.php.net%2Fmanual%2F%5C&y=1999"info.php3?id=$id\">$name</a></td>\n".
 14           "  <td>$salary</td>\n".
 15           " </tr>\n");
 16 }
 17 
 18 ?>
 19 
 20 </table>
 21       

See also: each(), array().


User Contributed Notes: list


arni@linux.is
23-Aug-1999 08:53
I've been trying to put the field names of the rows I want to select from the table in a $fields variable, like this:<br><br>
$fields = 'id, name, salary';
$result = mysql($conn, "SELECT $fields FROM employees");
$fields = '$'.str_replace(", ",', $',"$fields");	

while (list($fields) = mysql_fetch_row($result)) {
    print("$fields");
}
<br><br> I also tried to eval() the $values, but that does not seem to work either. I spent few hours trying to find out how to do this, but...there is no solution. list() re-creates the $values variable as a one variable, not three variables as shown in earlier code.


siggma@xs4all.be
08-Oct-1999 09:09
At first I thought that list(...) creates an array of references, so that
$a='x'; $b='y'; $c='z';
$d=list($a,$b,$c);
$d[1]='OK';
print $b;
would give 'OK', the new value of $b put there through the reference in $d[1]; But no, list(...) is a function that requires to be assigned an array to...


evergod@dcnetsolutions.net
20-Jan-2000 09:55
I am trying to edit a certain portion of a file, which has lines individually containing something like this:
user;name;email;score
I need to change the "score" part of one of those lines when I come to a specific "user". I tried to use a while loop with list($key, $val) and change the $val variable to one incremented when it came to $key == 4, but it seems like it did not change the value of it. I use implode() to put the variables back together... here is my code:
$fp = file("Agents/list.dat");   
while(list($key,$val)=each($fp)) 
{ 
	$array = explode(";",$val); 
	while(list($key2,$val2)=each($array)) 
		if ($key2 == 3)
		{
			$val2 = 1;
			$array2[$x+=1] = implode(";", $array);
		}
}

$newfp = implode("<br>\n", $array2);

print("$newfp");



gs@e-nova.com.sg
18-Feb-2000 02:32
Suppose a list of three items is returned and you are only interested in items one and three, you can skip assigning item two by
list($one, , $three) = some_function();



 About Notes


Previous page
 ksort
next 
Next page



Site Statistics


Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.