Jump to content

double parentheses


samsplug

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/173706-double-parentheses/
Share on other sites

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 :)

Link to comment
https://forums.phpfreaks.com/topic/173706-double-parentheses/#findComment-915655
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/173706-double-parentheses/#findComment-915755
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.