【问题标题】:How to color x and y coordinates in php grid table如何在php网格表中为x和y坐标着色
【发布时间】:2017-03-31 08:57:17
【问题描述】:

我有一个网格表。现在,我的表 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'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 );
    }

我的输出如下:

__________
|r |  |  |
|__|__|__| 
|r |r |  |
|__|__|__|

用颜色更改此$grid[ $curr['x'] ][ $curr['y'] ] = substr( $name, 0, 1 ); 的最佳方法是什么?我应该使用 css 还是可以使用 PHP?

【问题讨论】:

    标签: php colors


    【解决方案1】:

    如果我对您的理解正确,您希望同一个字母使用相同的颜色;所以所有的'A'都是红色的?

    您可以将颜色列表添加到数组中...

    $color = ['A'=>'FF0000','B'=>'00FF00',...,...]
    

    ...让您的代码输出...

    "style='background-color: #".$color[$letter]."'" 
    

    如果您担心内联样式,您甚至可以更改类名的十六进制值并获得一个不错的 sass 解决方案。

    有关更多信息,请参阅http://thesassway.com/intermediate/if-for-each-while

    【讨论】:

    • 所以它应该看起来像:$grid[ $curr['x'] ][ $curr['y'] ] = $color 还是没有?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多