PHP/Utility Function/list
Содержание
Each line is converted into an array
<source lang="html4strict">
<?
$filename="data.txt"; $filearray = file($filename); if ($filearray) { while (list($var, $val) = each($filearray)) { ++$var; $val = trim($val); print "Line $var: $val
"; } } else { print "Could not open $filename.\n"; }
?>
</source>
Extracting Values from an Array Using list()
<source lang="html4strict">
<?php
$scores = array(88, 75, 91, 84); list($maths, $english, $history, $biology) = $scores;printf("
Maths: %d; English: %d; History: %d; Biology: %d.
\n",$maths, $english, $history, $biology);
?>
</source>
list($maths, $english, , $biology) = $scores;
<source lang="html4strict">
<?php
$scores = array(88, 75, 91, 84); list($maths, $english, , $biology) = $scores;@printf("
Maths: %d; English: %d; History: %d; Biology: %d.
\n",$maths, $english, $history, $biology);
?>
</source>
Using the list() function.
<source lang="html4strict">
<?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"; ?>
</source>