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

PHP Home Page

Manual Table of Contents
Up to Arrays
Quick Reference
English version of this pageGerman version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
Arrays
* array
* array_count_values
* array_diff
* array_flip
* array_intersect
* array_keys
* array_merge
* array_merge_recursive
* array_multisort
* array_pad
* array_pop
* array_push
* array_rand
* 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
 Updated
Sat, 12 Aug 2000
next 
Next page


list

(unknown)

list --  配列と同様の形式で、複数の変数への代入を行います

説明

void list(...);

array() と同様に、この関数は実際には関数 ではなく言語の構成要素です。list()は、 単一の操作で一連の変数に値を割り当てるために使われます。

例 1. list()の例


<table>
 <tr>
  <th>従業員名</th>
  <th>給与</th>
 </tr>

<?php

$result = mysql($conn, "SELECT id, name, salary FROM employees");
while (list($id, $name, $salary) = mysql_fetch_row($result)) {
    print(" <tr>\n".
          "  <td><a href=/old?u=http%3A%2F%2Fwww.php.net%2Fmanual%2Fja%2F%5C&y=1999"info.php3?id=$id\">$name</a></td>\n".
          "  <td>$salary</td>\n".
          " </tr>\n");
}

?>

</table>
      

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:


<pre>
$fields = 'id, name, salary';
$result = mysql($conn, "SELECT $fields FROM employees");
$fields = '$'.str_replace(", ",', $',"$fields");

while (list($fields) = mysql_fetch_row($result)) {
print("$fields");
}
</pre>



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
<pre>
$a='x'; $b='y'; $c='z';
$d=list($a,$b,$c);
$d[1]='OK';
print $b;
</pre>
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:
<PRE>user;name;email;score</PRE>
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:

<PRE>$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("
\n", $array2);

print("$newfp");</PRE>



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
<pre>
list($one, , $three) = some_function();
</pre>



martin@hkhotmail.com
02-Aug-2000 04:53
Is that had any easy way to convert the value in assocative array to a new var. that the name is its key? Like:

/* $array = $mysql_fetch_array($handler, MYSQL_ASSOC); */

And want every val assigned to its key,

$col1=$array['col1']; /*a new var named $col1 with value $array['col1']*/


I tried use while...each and list to do, but both no work

Thx a lot.



moosh@phpfrance.com
05-Aug-2000 01:47
list($a,$b,$c)=$myArray



$myArray must be a scalar array and not an associative array.



moosh@phpfrance.com
05-Aug-2000 01:48
list($a,$b,$c)=$myArray



$myArray must be a scalar array and not an associative array.



 About Notes


Previous page
 ksort
 Updated
Sat, 12 Aug 2000
next 
Next page





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.