Comunitatea PHP Romania
 

 
list

list

(PHP 3, PHP 4, PHP 5 )

list --  Assign variables as if they were an array

Description

void list ( mixed ...)

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

Notã: list() only works on numerical arrays and assumes the numerical indices start at 0.

Exemplu 1. list() examples

<?php

$info
= array('coffee', 'brown', 'caffeine');

// Listing all the variables
list($drink, $color, $power) = $info;
print
"$drink is $color and $power makes it special.\n";

// Listing some of them
list($drink, , $power) = $info;
print
"$drink has $power.\n";

// Or let's skip to only the third one
list( , , $power) = $info;
print
"I need $power!\n";

?>

Exemplu 2. An example use of list()

<table>
<tr>
  <th>Employee name</th>
  <th>Salary</th>
</tr>

<?php

$result
= mysql_query ("SELECT id, name, salary FROM employees",$conn);
while (list (
$id, $name, $salary) = mysql_fetch_row ($result)) {
    print (
" <tr>\n".
           
"  <td><a href=\"info.php?id=$id\">$name</a></td>\n".
           
"  <td>$salary</td>\n".
           
" </tr>\n");
}

?>

</table>

See also each(), array() and extract().

Ultimele discutii in forum RSS Forum

Ultimele articole Ultimele articole

Top membri

Pirahna Pirahna
acasa , in pat
carco carco
Bucuresti
Birkoff Birkoff
Bucuresti
Mascka Mascka
Braila
raul_ raul_
whooper whooper
Toronto ON
mihaitha mihaitha
Sibiu
gabysolomon gabysolomon
Bacau
oriceon oriceon
Constanta
garlicinicolae garlicinicolae

Newsletter


Email:
 inscriere
 renuntare
 
 Arhiva newsletter

Parteneriat

Copyright © 2001-2008 PHP Romania Add PHPRomania to Google Add PHPRomania to Del.icio.us Add PHPRomania to Stumbleupon Add PHPRomania to Yahoo! Add PHPRomania to Digg Add PHPRomania to Blink Adverse Credit Remortgage | Pay Day Loans | Mobile Phones | Mortgages | Life Insurance
Ads: Partener Way2Web Nework: gazduire web | inregistrare domenii | web design | imobiliare | web hosting
Powered by Simplis