Код: Выделить всё
function register()
{
$data = $this->sample->register1();
$prev = '';
$next = '';
$output = '';
foreach ($data as $f) {
$next = $f['registercolor'];
switch ($f['registercolor']) {
case RED:
$btn = "bg-danger";
break;
case BLUE:
$btn = "bg-primary";
break;
case GREEN:
$btn = "bg-success";
break;
case YELLOW:
$btn = "bg-warning";
break;
default:
$btn = "bg-primary";
break;
}
if ($prev === $next || $prev === '' || $next === YELLOW || $next === GREEN) {
$prev = $next;
$output .='';
} else {
$prevRe = $nextRe;
}
$output .=''.$f['registerID'].'';
}
$output .= ' ';
echo json_encode($output);
}
Вот мое другое решение < /p>
контроллер: < /p>
Код: Выделить всё
const RED = 'red',
BLUE = 'blue',
GREEN = 'green',
YELLOW = 'yellow';
function register()
{
$data = $this->sample->register1();
$prev = '';
$next = '';
$output = '';
foreach ($data as $f) {
$next = $f['registercolor'];
switch ($f['registercolor']) {
case RED:
$btn = "bg-danger";
break;
case BLUE:
$btn = "bg-primary";
break;
case GREEN:
$btn = "bg-success";
break;
case YELLOW:
$btn = "bg-warning";
break;
default:
$btn = "bg-primary";
break;
}
if ($prev === $next || $prev === '' || $next === YELLOW || $next === GREEN) {
$output .= 'ʘ';
} else {
$output .= 'ʘ';
}
}
// prevent change from same color like this case : RED -> YELLOW -> RED
if ($next !== YELLOW && $next !== GREEN) {
$prev = $next;
}
$output += '';
echo json_encode($output);
}
Подробнее здесь: https://stackoverflow.com/questions/691 ... -structure
Мобильная версия