Search code examples
phppostfix-operatorprefix-operator

Different server different output in same php version


I have two PHP server where i installed same php 5.6.8, but one server is windows and another is linux . When i write this code the output of code is different on different server.

$x=5;
echo $x."".++$x."".$x++;

Why does it give different answers on different server?


Solution

  • Have you considered issues with your Linux machine? I ran your code on my linux machine and I get 5, 6, 6.

    Most Linux machines have gcc installed. Why don't you try putting this code in a file and compiling it with gcc. It will create an a.out file which is binary and you can run it. See if you have the same problem:

    #include<stdio.h>
    
    main()
    {
            int x = 5;
            printf("%d ", x);
            printf("%d ", ++x);
            printf("%d", x++);
    }