Skip to content

Instantly share code, notes, and snippets.

@kirilkirkov
Created July 17, 2015 13:40
Show Gist options
  • Save kirilkirkov/2884423e5198a7a38db2 to your computer and use it in GitHub Desktop.
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
<?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