Created
July 17, 2015 13:40
-
-
Save kirilkirkov/2884423e5198a7a38db2 to your computer and use it in GitHub Desktop.
Return highlight hex color for string. Can be used in loop. Return same color for same strings and different for others
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_highlight($str) { | |
$colors = array('#ccddee', '#ffdddd', '#ddccee', | |
'#ddeecc', '#eeccdd', '#cceedd', | |
'#eeddcc', '#ddddff', '#ddffdd'); | |
shuffle($colors); | |
static $prev_color = ''; | |
static $arr = array(); | |
if (!in_array($str, $arr)) { | |
$arr[] = $str; | |
foreach ($colors as $color) { | |
if ($color != $prev_color) { | |
$prev_color = $color; | |
break; | |
} | |
} | |
$arr[$str] = $prev_color; | |
} | |
return $arr[$str]; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment