0
我的下面的代碼計算門票號碼並根據字母表將它們存儲到數組中。例如一張票將以字母開頭,X121211將以$ X存儲。然後,如果數組不爲空,則顯示它們。我希望能夠突出顯示這些字母。例如突出顯示以x開頭的顏色和另一個字母的其餘部分。是否有動態的方式來做到這一點,因爲這可能每週都會改變。我希望這是有道理的。字母表中的彩色字母
$returned = array();
$returned["A"] = array();
$returned["B"] = array();
$returned["C"] = array();
$returned["D"] = array();
$returned["E"] = array();
$returned["F"] = array();
$returned["G"] = array();
$returned["H"] = array();
$returned["I"] = array();
$returned["J"] = array();
$returned["K"] = array();
$returned["L"] = array();
$returned["M"] = array();
$returned["N"] = array();
$returned["O"] = array();
$returned["P"] = array();
$returned["Q"] = array();
$returned["R"] = array();
$returned["S"] = array();
$returned["T"] = array();
$returned["U"] = array();
$returned["V"] = array();
$returned["W"] = array();
$returned["X"] = array();
$returned["Y"] = array();
$returned["Z"] = array();
foreach($skin as $x) {
// $content .= "<tr>
// <td>" . $x[0] . "</td>
// <td>" . $x[1] . "</td>
// </tr>";
$bundletotal += $x[1];
}
$bundle += $bundletotal;
foreach($skin as $x) {
if (strpos($x[0], "A") !== FALSE) {
$returned["A"][] = $x;
}
if (strpos($x[0], "B") !== FALSE) {
$returned["B"][] = $x;
}
if (strpos($x[0], "C") !== FALSE) {
$returned["C"][] = $x;
}
if (strpos($x[0], "D") !== FALSE) {
$returned["D"][] = $x;
}
if (strpos($x[0], "E") !== FALSE) {
$returned["E"][] = $x;
}
if (strpos($x[0], "F") !== FALSE) {
$returned["F"][] = $x;
}
if (strpos($x[0], "G") !== FALSE) {
$returned["G"][] = $x;
}
if (strpos($x[0], "H") !== FALSE) {
$returned["H"][] = $x;
}
if (strpos($x[0], "I") !== FALSE) {
$returned["I"][] = $x;
}
if (strpos($x[0], "J") !== FALSE) {
$returned["J"][] = $x;
}
if (strpos($x[0], "K") !== FALSE) {
$returned["K"][] = $x;
}
if (strpos($x[0], "L") !== FALSE) {
$returned["L"][] = $x;
}
if (strpos($x[0], "M") !== FALSE) {
$returned["M"][] = $x;
}
if (strpos($x[0], "N") !== FALSE) {
$returned["N"][] = $x;
}
if (strpos($x[0], "O") !== FALSE) {
$returned["O"][] = $x;
}
if (strpos($x[0], "Q") !== FALSE) {
$returned["Q"][] = $x;
}
if (strpos($x[0], "R") !== FALSE) {
$returned["R"][] = $x;
}
if (strpos($x[0], "S") !== FALSE) {
$returned["S"][] = $x;
}
if (strpos($x[0], "T") !== FALSE) {
$returned["T"][] = $x;
}
if (strpos($x[0], "U") !== FALSE) {
$returned["U"][] = $x;
}
if (strpos($x[0], "V") !== FALSE) {
$returned["V"][] = $x;
}
if (strpos($x[0], "W") !== FALSE) {
$returned["W"][] = $x;
}
if (strpos($x[0], "X") !== FALSE) {
$returned["X"][] = $x;
}
if (strpos($x[0], "Y") !== FALSE) {
$returned["Y"][] = $x;
}
if (strpos($x[0], "Z") !== FALSE) {
$returned["Z"][] = $x;
}
}
$A = count(array_unique($returned["A"], SORT_REGULAR));
$B = count(array_unique($returned["B"], SORT_REGULAR));
$C = count(array_unique($returned["C"], SORT_REGULAR));
$D = count(array_unique($returned["D"], SORT_REGULAR));
$E = count(array_unique($returned["E"], SORT_REGULAR));
$F = count(array_unique($returned["F"], SORT_REGULAR));
$G = count(array_unique($returned["G"], SORT_REGULAR));
$H = count(array_unique($returned["H"], SORT_REGULAR));
$I = count(array_unique($returned["I"], SORT_REGULAR));
$J = count(array_unique($returned["J"], SORT_REGULAR));
$K = count(array_unique($returned["K"], SORT_REGULAR));
$L = count(array_unique($returned["L"], SORT_REGULAR));
$M = count(array_unique($returned["M"], SORT_REGULAR));
$N = count(array_unique($returned["N"], SORT_REGULAR));
$O = count(array_unique($returned["O"], SORT_REGULAR));
$P = count(array_unique($returned["P"], SORT_REGULAR));
$Q = count(array_unique($returned["Q"], SORT_REGULAR));
$R = count(array_unique($returned["R"], SORT_REGULAR));
$S = count(array_unique($returned["S"], SORT_REGULAR));
$T = count(array_unique($returned["T"], SORT_REGULAR));
$U = count(array_unique($returned["U"], SORT_REGULAR));
$V = count(array_unique($returned["V"], SORT_REGULAR));
$W = count(array_unique($returned["W"], SORT_REGULAR));
$X = count(array_unique($returned["X"], SORT_REGULAR));
$Y = count(array_unique($returned["Y"], SORT_REGULAR));
$Z = count(array_unique($returned["Z"], SORT_REGULAR));
$content .= "
<table border='5'>
<td width='50%' valign='top'>
<p><b>Monday</b></p> <p>";
$total = 0;
if ($A>0) {
$content .= " A: $A ";
$total+= $A;
}
if ($B>0) {
$content .= " B: $B ";
$total+= $B;
}
if ($C>0) {
$content .= " C: $C ";
$total+= $C;
}
if ($D>0) {
$content .= " D: $D ";
$total+= $D;
}
if ($E>0) {
$content .= " E: $E ";
$total+= $E;
}
if ($F>0) {
$content .= " F: $F ";
$total+= $F;
}
if ($G>0) {
$content .= " G: $G ";
$total+= $G;
}
if ($H>0) {
$content .= " H: $H ";
$total+= $H;
}
if ($I>0) {
$content .= " I: $I ";
$total+= $I;
}
if ($J>0) {
$content .= " J: $J ";
$total+= $J;
}
if ($K>0) {
$content .= " K: $K ";
$total+= $K;
}
if ($M>0) {
$content .= " M: $M ";
$total+= $M;
}
if ($N>0) {
$content .= " N: $N ";
$total+= $N;
}
if ($O>0) {
$content .= " O: $O ";
$total+= $O;
}
if ($P>0) {
$content .= " P: $P ";
$total+= $P;
}
if ($Q>0) {
$content .= " Q: $Q ";
$total+= $Q;
}
if ($R>0) {
$content .= " R: $R ";
$total+= $R;
}
if ($S>0) {
$content .= " S: $S ";
$total+= $S;
}
if ($T>0) {
$content .= " T: $T ";
$total+= $T;
}
if ($U>0) {
$content .= " U: $U ";
$total+= $U;
}
if ($V>0) {
$content .= " V: $V ";
$total+= $V;
}
if ($W>0) {
$content .= " W: $W ";
$total+= $W;
}
if ($X>0) {
$content .= " X: $X ";
$total+= $X;
}
if ($Y>0) {
$content .= " Y: $Y ";
$total+= $Y;
}
if ($Z>0) {
$content .= " Z: $Z ";
$total+= $Z;
}
你可以更清楚明確地說明這個問題:「有些星期有特殊的票號,可以說v和q,我需要在顏色上使用高字母,在一種顏色上使用v和q,剩下一種顏色」 ?它幫助我們幫助你。 –
我認爲「幹」原則(不要重複自己)需要在這裏應用。這種複製和粘貼編碼方案是危險的,這使得錯誤很容易滑入。爲什麼每個字母使用一個數組,當你可以使用多維數組時? –
如果這只是爲了提高可見性,使用jquery添加顏色可以節省大量的服務器處理時間。 –