0

我有一个字母清单。我将这个字母列表与一个字母数组进行比较,并得到区别。然后将它们放在一个数组中,这样我就可以将它作为一个列表输出。

//start the array
$alphabet = array();

//the letters I'm using
$letters = array('A','B','C','D','E','F','G','H','I','J','L','M','N','O','P','R','S','T','V');
//place into true array
foreach($letters as $l)
     $alphabet['true'][] = $l;

//alphabet array, place into false array
foreach (range('A','Z') as $char)
     $alphabet['false'][] = $char;

//the not used array by getting the difference of true and false arrays
$alphabet['actual'] = array_diff($alphabet['false'], $alphabet['true']);

//merge the arrays into one array
$new = array_merge($alphabet['true'],$alphabet['actual']);

//sort them naturally
natsort($new);

//list the results
echo  "All together now: <pre>"; print_r($new); echo "</pre>";

有没有办法在将每个不同的数组键值放入大数组之前对其进行样式设置?沿着未使用的字母线的东西是不同的颜色?还是我以错误的方式解决这个问题?感谢您的任何见解。

4

1 回答 1

2

如果它在我那里,我会做这样的事情。

//start the array
$alphabet = array();

//the letters I'm using
$used = array('A','B','C','D','E','F','G','H','I','J','L','M','N','O','P','R','S','T','V');
$alphabet = range('A','Z');
echo "<ul>";
foreach($alphabet as $letter){
    if (in_array($letter, $used)){
        echo "<li class='used'>".$letter."</li>";
    } else {
        echo "<li class='unused'>".$letter."</li>";
    }
}
echo "</ul>";

并制定几个 CSS 规则

li.used { color:green; }
li.unused { color:red; }
于 2013-05-30T21:42:30.730 回答