note 119197 added to language.operators.precedence
| From: | BilalMustafa | Date: | Mon, 18 Apr 2016 15:42:35 +0000 |
| Subject: | note 119197 added to language.operators.precedence | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205264@lists.php.net to get a copy of this message | ||
Another way to sort out the problem mentioned by "nicoolasens at gmail dot com" and
"Antistone" is:
<?php
$x = 4;
echo "x minus one equals " . $x-1 . ", or so I hope";
?>
will print "-1, or so I hope"
Solution:
We can wrap the methematical part in "()" and let the parser tell to solve it first in
other words here we can get the benefit of higher precedence of "()" So if we rewrite the
example as:
<?php
$x = 4;
echo "x minus one equals " . ($x-1) . ", or so I hope";
?>
The answer will be according to our expectation which is:
"x minus one equals 3, or so I hope"
----
Server IP: 72.52.91.14
Probable Submitter: 94.10.224.69
----
Manual Page -- http://php.net/manual/en/language.operators.precedence.php
Edit -- https://master.php.net/note/edit/119197
Del: integrated -- https://master.php.net/note/delete/119197/integrated
Del: useless -- https://master.php.net/note/delete/119197/useless
Del: bad code -- https://master.php.net/note/delete/119197/bad+code
Del: spam -- https://master.php.net/note/delete/119197/spam
Del: non-english -- https://master.php.net/note/delete/119197/non-english
Del: in docs -- https://master.php.net/note/delete/119197/in+docs
Del: other reasons-- https://master.php.net/note/delete/119197
Reject -- https://master.php.net/note/reject/119197
Search -- https://master.php.net/manage/user-notes.php