[Solved] Unexpected T_ELSE [closed]


This would be a lot simpler using a switch/case logic scheme. I have re-coded what you had up there using switch/case and this might be a good intro for you to learn switch/case. You had some extra ( ) in one of the if statements above. I hope this helps, friend:

<?
$unix_time = 6734;
echo howLongAgo($unix_time);

function howLongAgo($time_difference){

// Swtich logic based on the time difference passed to this function, sets the english string and what number the difference needs to be divided by
    switch($time_difference){
         case ($time_difference < 60):
              $string = " second";
              break;
         case ($time_difference >= 60 && $time_difference < 3600):
              $string = " minute";
              $divider = 60;
              break;
         case ($time_difference >= 3600 && $time_difference < 86400):
              $string = " hour";
              $divider = 3600;
              break;
         case ($time_difference >= 86400 && $time_difference < 2629743):
              $string = " day";
              $divider = 86400;
              break;
         case ($time_difference >= 2629743 && $time_difference < 31556926):
              $string = " month";
              $divider = 2629743;
              break;
         case ($time_difference >= 31556926):
              $string = " year";
              $divider = 31556926;
              break;
    }

// If a divider value is set during the switch, use it to get the actual difference
if($divider){$diff = round($time_difference / $divider);}else{$diff = round($time_difference);}
// If the difference does not equal 1, pluralize the final result EG: hours, minutes, seconds
if($diff != 1){$pluralize="s";}
// Concatenate all variables together and return them
$final =  $diff . $string . $pluralize . " ago";
return $final;

}
?>

2

solved Unexpected T_ELSE [closed]