Please explain me what's the difference between this two:
1. $ratio = $uploaded / $downloaded; 2. $ratio = (($downloaded > 0) ? ($uploaded / $downloaded) : 0);
So which one is better to use?
The first one is only some calcualtion and the second one is a shortcut for a if/else clause.
The second example uses the ternary operator e.g. var = condition ? val : val. This is a shorthand for an if/else statement:
if( $downloaded > 0 ) { $ratio = $uploaded / $downloaded; } else { $ratio = 0; }
Edit: beaten to it by Olaf 😉
fr600 wrote:So which one is better to use?
Drawback with version 1: if $downloaded is 0, an error will occur when you try to divide by 0. This can obviously not happen with version 2.