Skip to content

Instantly share code, notes, and snippets.

@tanakahisateru
Last active April 22, 2019 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanakahisateru/c1d51db833f29706a303725a4b5fa167 to your computer and use it in GitHub Desktop.
Save tanakahisateru/c1d51db833f29706a303725a4b5fa167 to your computer and use it in GitHub Desktop.
The refactoring
<?php
foreach ($cells $ $cell) {
//
switch ($tdcnt++ % 3) {
case 0:
$cls = 'c_td1';
break;
case 1:
$cls = 'c_td2';
break;
case 2:
$cls = 'c_td3';
break;
}
$cls = ($tdcnt++ % 2) ? 'c_td1' : 'c_td2';
//
}
<?php
foreach ($cells $ $cell) {
//
$cls = 'c_td' . ($tdcnt++ % 3 + 1);
$cls = ($tdcnt++ % 2) ? 'c_td1' : 'c_td2';
//
}
<?php
foreach ($cells $ $cell) {
//
$cls = ($tdcnt % 2) ? 'c_td1' : 'c_td2';
$tdcnt += 2;
//
}
<?php
foreach ($cells $ $cell) {
//
$cls = 'c_td1';
//
}
<?php
$cls = 'c_td1';
foreach ($cells $ $cell) {
//
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment