samsplug Posted September 9, 2009 Share Posted September 9, 2009 below is an extract of code which i have copied from a book which i have been studying... The code is a segment from a script about paginating query results. I understand almost all of the below code except the ... (($display * ($i – 1))) ... Why is a double parentheses used around the $display variable. For ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo ‘< a href=”view_users.php?s=’ . (($display * ($i – 1))) . ‘&p=’ . $pages . ‘”>’ . $i . ‘</a> ‘; } else { echo $i . ‘ ‘; } } I'd be really grateful if someone could explain that to me thanks Quote Link to comment Share on other sites More sharing options...
SilveR316 Posted September 9, 2009 Share Posted September 9, 2009 There is no reason for it. You can remove the parentheses and it will function just the same. Just don't remove the ones from around $i-1. I guess its the author's personal coding style preference. Possibly to make it easier to read. Quote Link to comment Share on other sites More sharing options...
samsplug Posted September 9, 2009 Author Share Posted September 9, 2009 There is no reason for it. You can remove the parentheses and it will function just the same. Just don't remove the ones from around $i-1. I guess its the author's personal coding style preference. Possibly to make it easier to read. Thats weird... They have no purpose at all?? Thanks for the quick reply Quote Link to comment Share on other sites More sharing options...
SilveR316 Posted September 9, 2009 Share Posted September 9, 2009 None whatsoever. You can nest it in 15 parentheses like that and it would do the exact same thing as not putting it in any at all. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted September 9, 2009 Share Posted September 9, 2009 it DOES make a difference - check your operator precedence. The concatenation operator takes precedence over mathematical ones so if you want any computation within a concatenated string it must be contained within parentheses. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.