a - b = (+a) + (-b) = (-b) + (+a) The argument is about the ternary operator though: #include<stdio.h> main() { int a = 1; printf("%s", (a == 1) ? "one" : (a == 2) ? "two" : "three"); } in C outputs: >> one So, why is PHP different? Tim-Hinnerk Heuer Twitter: @geekdenz Blog: http://www.thheuer.com On 18 October 2013 13:59, Tamara Temple <tamouse.lists@xxxxxxxxx> wrote: > Ternary operator works the same in every language I've encountered… you > can expand every such statement to an if-then-else if it makes you feel > better. Not every operator in math is transitive, either. a - b is not the > same as b - a, for example. > > > On Oct 17, 2013, at 7:51 PM, Tim-Hinnerk Heuer <th.heuer@xxxxxxxxx> wrote: > > > No, but when you add stuff it gets the same result from left to right as > > from right to left. > > So, the ternary operator is more related to logic, even though logic > > belongs to math. > > > > Tim-Hinnerk Heuer > > > > Twitter: @geekdenz > > Blog: http://www.thheuer.com > > > > > > On 18 October 2013 13:49, Daniel <danielx386@xxxxxxxxx> wrote: > > > >> On Fri, Oct 18, 2013 at 11:46 AM, Tim-Hinnerk Heuer <th.heuer@xxxxxxxxx > > > >> wrote: > >>> Hi, > >>> > >>> I've been a PHP programmer for several years now and have a bit of a > >>> love-hate relationship with it. It's great for doing something quickly, > >>> especially web stuff, but recently I have heard people moaning about > PHP > >> a > >>> lot and did some research and found this: > >>> > >>> http://webonastick.com/php.html > >>> > >>> One thing I had to get my head around is this: > >>> The ternary operator > >>> <?php > >>> $foo = 1; > >>> print(($foo == 1) ? "uno" : ($foo === 2) ? "dos" : "tres"); > >>> print("\n"); > >>> > >>> outputs > >>>>> dos > >>> > >>> because the operator is left-to-right associative instead of > >> right-to-left > >>> as in other languages. I was thinking there must be a reason for this. > >>> Speed? Is it faster to evaluate/implement all operators as > left-to-right? > >>> > >>> I noticed that the above could easily be fixed by saying: > >>> > >>> <?php > >>> $foo = 1; > >>> print(($foo == 1) ? "uno" : (($foo === 2) ? "dos" : "tres")); > >>> print("\n"); > >>> > >>> outputs > >>>>> uno > >>> > >>> Was this a deliberate design decision or is it a flaky implementation > of > >>> the ternary operator? > >>> > >>> Tim-Hinnerk Heuer > >>> > >>> Twitter: @geekdenz > >>> Blog: http://www.thheuer.com > >> > >> > >> Maybe it just me but I look at it the same as math, you don't add > >> something up from right to left do you? > >> > >