PHP/Utility Function/list — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 10:37, 26 мая 2010
Содержание
Each line is converted into an array
<?
$filename="data.txt";
$filearray = file($filename);
if ($filearray) {
while (list($var, $val) = each($filearray)) {
++$var;
$val = trim($val);
print "Line $var: $val<br />";
}
} else {
print "Could not open $filename.\n";
}
?>
Extracting Values from an Array Using list()
<?php
$scores = array(88, 75, 91, 84);
list($maths, $english, $history, $biology) = $scores;
printf("<p>Maths: %d; English: %d; History: %d; Biology: %d.</p>\n",
$maths, $english, $history, $biology);
?>
list($maths, $english, , $biology) = $scores;
<?php
$scores = array(88, 75, 91, 84);
list($maths, $english, , $biology) = $scores;
@printf("<p>Maths: %d; English: %d; History: %d; Biology: %d.</p>\n",
$maths, $english, $history, $biology);
?>
Using the list() function.
<?php
$net_address = array("192.168.1.101", "255.255.255.0", "192.168.1.1");
list($ip_addr, $net_mask, $gateway) = $net_address;
echo "ip addr = $ip_addr\n";
echo "net mask = $net_mask\n";
echo "gateway = $gateway\n";
?>