Archives for: February 2016

How to swap two numbers without using a temporary variable in PHP ?

We have two variables (parameters) “x” & “y”, here we do swap of two variables without using a third variable (parameters).

1) Swap numbers using Arithmetic Operators –
In below example we use addition and subtraction operation to do swap of 2 numbers

In below example we use multiplication and division operation to do swap of 2 numbers

 

2) Swap numbers using Bitwise XOR Operators –

Note:
In multiplication, we can not able to use 0 (zero), because of it make multiplication result as zero.

Your comments are appreciated!

Till than Happy Coding 🙂

Learn, Share and Grow

Learn, Share and Grow

Learn, Share and Grow

A journey of a thousand miles begins with a single step.

– Lao-tzu, The Way of Lao-tzu

Chinese philosopher (604 BC – 531 BC)

As a web developer i thought to create a knowledge sharing platform via ILovePHP.net. In web development, there are endless technologies are arriving every day, and same time we found huge opportunities to test our skills and potential. On same path we all are finding some way to share our experience of this journey. This is all about ILovePHP.net.

My purpose and motto to create this blog is to create knowledge sharing point for all whom need it. It’s an open platform for everyone to share their experience knowledge, Ideas, technology updates for everyone. To share articles on ILovePHP.net, just do send of your article on my mail id(sagarsdeshmukh91@gmail.com). After review i will publish it with your name. Important thing is the article content should be neat and clean, should not copy right prone and not steal from other blogs.

Any suggestions, improvement and feedbacks are appreciated.

Thanks a lot and Happy Coding 🙂