我是新來的PHP和一般網頁開發(第一大項目)。我主要解決了這個問題,但我認爲他們的方式我做到了效率不高(不聰明),但仍然沒有妥善解決,這就是爲什麼我想知道您的意見。以高效的方式填充矩陣
我有語言(student_language)的陣列。在每種語言中,我們都有一個名字的字符串和4個整數(用這種語言的技能的標點符號)。 我將這些信息轉換爲PDF格式,並創建了一個HTML表格來呈現那裏的語言。 所以,我必須用我的數組填充它。在這裏,我有我的問題:
- 首先,我想我使用了很多變量:你看到一種方式有更少的?
- 第二,如您在下面的代碼中看到的,「Andere(Others)」類別中有多種語言。所以,如果此類別中有多種語言,我想添加另一行。任何提示?
代碼:提前
foreach ($student_language as $sl){
//Dutch
if ($sl['StudentLanguage']['language_id'] == '5'){
$ned_listening=$sl['StudentLanguage']['listening'];
$ned_spoken=$sl['StudentLanguage']['speaking'];
$ned_reading=$sl['StudentLanguage']['reading'];
$ned_written=$sl['StudentLanguage']['written'];
}
//French
if ($sl['StudentLanguage']['language_id'] == '2'){
$fre_listening=$sl['StudentLanguage']['listening'];
$fre_spoken=$sl['StudentLanguage']['speaking'];
$fre_reading=$sl['StudentLanguage']['reading'];
$fre_written=$sl['StudentLanguage']['written'];
}
//English
if ($sl['StudentLanguage']['language_id'] == '1'){
$eng_listening=$sl['StudentLanguage']['listening'];
$eng_spoken=$sl['StudentLanguage']['speaking'];
$eng_reading=$sl['StudentLanguage']['reading'];
$eng_written=$sl['StudentLanguage']['written'];
}
//Flemish
if ($sl['StudentLanguage']['language_id'] == '5'){
$fle_listening=$sl['StudentLanguage']['listening'];
$fle_spoken=$sl['StudentLanguage']['speaking'];
$fle_reading=$sl['StudentLanguage']['reading'];
$fle_written=$sl['StudentLanguage']['written'];
}
//Others : German, Polish, Greek, Portuguese, Russian, Italian , Spanish
if ($sl['StudentLanguage']['language_id'] == '6' || '7' || '8' || '9' || '10' || '11' || '12'){
$oth_listening=$sl['StudentLanguage']['listening'];
$oth_spoken=$sl['StudentLanguage']['speaking'];
$oth_reading=$sl['StudentLanguage']['reading'];
$oth_written=$sl['StudentLanguage']['written'];
}
}
$talenkennis= <<<EOD
<br />
<br />
<br />
<table border="1" align="center">
<tr>
<th></th>
<th>Begrijpen</th>
<th>Spreken</th>
<th>Lezen</th>
<th>Schrijven</th>
</tr>
<tr>
<td>Nederlands</td>
<td>$ned_listening</td>
<td>$ned_spoken</td>
<td>$ned_reading</td>
<td>$ned_written</td>
</tr>
<tr>
<td>Frans</td>
<td>$fre_listening</td>
<td>$fre_spoken</td>
<td>$fre_reading</td>
<td>$fre_written</td>
</tr>
<tr>
<td>Engels</td>
<td>$eng_listening</td>
<td>$eng_spoken</td>
<td>$eng_reading</td>
<td>$eng_written</td>
</tr>
<tr>
<td>Duits</td>
<td>$fle_listening</td>
<td>$fle_spoken</td>
<td>$fle_reading</td>
<td>$fle_written</td>
</tr>
<tr>
<td>Andere</td>
<td>$oth_listening</td>
<td>$oth_spoken</td>
<td>$oth_reading</td>
<td>$oth_written</td>
</tr>
<tr>
(Noties = 1 , Voldoende = 2 , Grondig = 3 , Moedertaal = 4) <br />
</tr>
</table>
EOD;
$pdf->writeHTML($talenkennis, true, false, false, false, '');
謝謝!
Alf。
從哪裏開始... – dqhendricks 2011-03-14 20:58:06