php - Division by zero with arrays -
alright, have array server query on game server holds information. made progress bar shows current amount of players. percentage of progress bar calculated this
<span style="width: ' . $data['gq_numplayers'] / $data['gq_maxplayers'] * 100 . '%;"></span>
now, if server offline problems array empty , division 0/0 , causes error. how bypass/solve this?
perhaps use of if
statement solution.
i.e.
if ($data['gq_maxplayers'] == 0) { echo '<span style="width: 0%;"></span>'; } else { echo '<span style="width: ' . $data['gq_numplayers'] / $data['gq_maxplayers'] * 100 . '%;"></span>'; }
Comments
Post a Comment