下面的代码统计了门票号,并根据字母将它们存储到数组中。例如,票证将以字母开头,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;
}
答案 0 :(得分:1)
以下代码与上述代码完全相同:
$returned = Array();
foreach(array_unique($skin) as $x) {
$returned[$x[0]] += 1;
}
$total = array_sum($returned);
$content = "";
foreach($returned as $k=>$v) {
$content .= " ".$k.": ".$v." ";
}
这比你的代码简单得多。
如果这不符合您的要求,请详细说明您想要的内容。