Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Swap two variables value without using third variable in php

    • 0
    • 2
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 261
    Comment on it

    Here is a method. How to swap two variables value without using third variable and temp variable.

    $a = 3;
    $b = 2;
    $a = $a + $b; // 3 + 2 = 5
    $b = $a - $b; // 5 - 2 = 3
    $a = $a - $b; // 5 - 3 = 2
    print $a;
    print $b;
    
    Output:
    2
    3 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: