-2

我正在尝试模拟一个工作产品并创建了一个 PHP 信息数组,我希望将其插入到一个包含 20-100 个值的表中(每个页面加载时随机)?

因此,从某种意义上说,该数组充当某种“数据库”,并生成一个包含 20-100 个值的随机表。

对于某些数组,例如$facilitiesand $room,我希望选择三个不同的值并将其插入表中。

我该怎么做呢?

这是我的数组:

<?php
// module code array
$moduleCode = array("XXX101","XXX107","XXX122","XXX123","XXX124","XXX201","XXX220","XXX256","ZZZ101","ZZZ106","ZZZ107","ZZZ108","ZZZ120","ZZZ150","ZZZ201","ZZZ231","ZZZ232","ZZZ249","ZZZ251","ZZZ290","ZZZ295","ZZZ301","YYY001","YYY003","YYY101","YYY102","YYY104","YYY104","YYY106","YYY107","YYY131","YYY140","YYY170","YYY180","YYY190","YYY201","YYY202","YYY220","YYY221","YYY251","YYY253","YYY255","YYY257","YYY259","YYY281","YYY800","YYY801","YYY802","NNN280","NNN290");
// random no of students between 20 and 400
$noStudents = rand(20, 400);
// day of the week
$day = array("1 - Mon","2 - Tues","3 - Wed","4 - Thu","5 - Fri");
// period of the day
$period = array("1 - 09:00","2 - 10:00","3 - 11:00","4 - 12:00","5 - 13:00","6 - 14:00","7 - 15:00","8 - 16:00","9 - 17:00");
// length of lecture
$lecture = rand(1, 7);
// weeks
$weeks = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15");
// facilities
$facilities = array("Blu-ray DVD Player","Chalk board","Computer","Data projector","Dual data projector","DVD/Video","Glass board","Induction loop","Interactive PC monitor","Loop system","Microphone","OHP","PA","PC & laptop audio","Plasma screen","Radio mic","Review","Twin data projector","Video/DVD","Visualizer","Wheelchair access","White board",
"White/green board");
// room preferences
$room = array("J110","CC011","U020","CC012","CC013","J001","A201","J002","GGB01","A001","J104","B111","U011","A203","K108","D002","D102","D109","D201","D202","G006","G007","CC014","K105","CC109","CC110","U012","K109","U112","CC111","K106","G002","G003","G004","CC113","K107","U013","U014","N326","BE025","SMB014","SMB017","SMB103","SMB104","SMB008","SMB010","SMB102","SMB105","SMB109","SMB108","Cope","HE010","JB021","XX019","JJ004","ZZ106","HE023","HE021","HE026","63.1.07","JJ018","NN006","ZZ105","ZZ103","63.1.08","JJ017","XX031","XX031a","T003","RT037","W001","S004","W004","RT033","RT040","W003","S174","S173","W002","RT027","X401","W005A","W005B","W005C","S177","W005D","W005E","W005F","S006","T210","KG107","KG109","KG111","KG112");
?>
4

1 回答 1

1

您可以创建一个表并使用循环来填充行。array_rand()可用于生成随机密钥。

只需添加更多<td>以获得您想要的所有字段。

<table>
<?php
for($i=0; $i<10;++$i){
echo '<tr>';
echo '<td>' . array_rand($moduleCode) .'</td>;
echo '</tr>';
}
?>
</table>
于 2012-11-05T06:06:08.633 回答