如何在php网格表中为x和y坐标着色
我有一张格子桌子。现在,我的表x和y坐标显示了键的第一个字母。我想用相同的颜色来改变这些坐标如何在php网格表中为x和y坐标着色,php,colors,Php,Colors,我有一张格子桌子。现在,我的表x和y坐标显示了键的第一个字母。我想用相同的颜色来改变这些坐标 for ( $i = 0; $i < $size; $i++ ) { # Create a temporary holder for our coordinates $curr = array( 'x' => $x, 'y' => $y ); # Add current grid position to the direction we'
for ( $i = 0; $i < $size; $i++ ) {
# Create a temporary holder for our coordinates
$curr = array( 'x' => $x, 'y' => $y );
# Add current grid position to the direction we're going
$curr[ $axis ] += $i;
# Add the first letter of the key name to the grid
$grid[ $curr['x'] ][ $curr['y'] ] = substr( $name, 0, 1 );
}
更改此
$grid[$curr['x'][$curr['y']]=substr($name,0,1)的最佳方法是什么代码>有颜色吗?我应该使用css还是可以使用PHP?如果我理解正确,您希望同一个字母使用相同的颜色;那么所有的A都是红色的
您可以将颜色列表添加到数组中
$color = ['A'=>'FF0000','B'=>'00FF00',...,...]
…并将您的代码输出
"style='background-color: #".$color[$letter]."'"
如果您担心内联样式,您甚至可以更改类名的十六进制值,并拥有一个很好的sass解决方案
请参阅以获取有关该属性的详细信息,因此它应该是:$grid[$curr['x']][$curr['y']]]=$color
还是no?
"style='background-color: #".$color[$letter]."'"