<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: How to SWAP values of two variables without using a third variable?</title>
	<atom:link href="http://www.mizanurrahman.com/2008/07/30/how-to-swap-values-of-two-variables-without-using-a-third-variable/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mizanurrahman.com/2008/07/30/how-to-swap-values-of-two-variables-without-using-a-third-variable/</link>
	<description>- weblog of Mizanur Rahman</description>
	<pubDate>Thu, 09 Sep 2010 01:15:58 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: booleandreams</title>
		<link>http://www.mizanurrahman.com/2008/07/30/how-to-swap-values-of-two-variables-without-using-a-third-variable/comment-page-1/#comment-760</link>
		<dc:creator>booleandreams</dc:creator>
		<pubDate>Sun, 14 Dec 2008 13:47:20 +0000</pubDate>
		<guid isPermaLink="false">http://booleandreams.wordpress.com/?p=66#comment-760</guid>
		<description>Hi Apu

Using a list /array is almost similar to using a variable. :)

we do not need to swap string, numbers will be good enough :)</description>
		<content:encoded><![CDATA[<p>Hi Apu</p>
<p>Using a list /array is almost similar to using a variable. <img src='http://www.mizanurrahman.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
we do not need to swap string, numbers will be good enough <img src='http://www.mizanurrahman.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tarek Mahmud apu</title>
		<link>http://www.mizanurrahman.com/2008/07/30/how-to-swap-values-of-two-variables-without-using-a-third-variable/comment-page-1/#comment-759</link>
		<dc:creator>Tarek Mahmud apu</dc:creator>
		<pubDate>Sun, 14 Dec 2008 07:55:58 +0000</pubDate>
		<guid isPermaLink="false">http://booleandreams.wordpress.com/?p=66#comment-759</guid>
		<description>mizan bhai 1st comment ta muse den pls.. tag er jonno tikmoto aseni..</description>
		<content:encoded><![CDATA[<p>mizan bhai 1st comment ta muse den pls.. tag er jonno tikmoto aseni..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tarek Mahmud apu</title>
		<link>http://www.mizanurrahman.com/2008/07/30/how-to-swap-values-of-two-variables-without-using-a-third-variable/comment-page-1/#comment-758</link>
		<dc:creator>Tarek Mahmud apu</dc:creator>
		<pubDate>Sun, 14 Dec 2008 07:52:44 +0000</pubDate>
		<guid isPermaLink="false">http://booleandreams.wordpress.com/?p=66#comment-758</guid>
		<description>Thanks for the post.. i just want to add more...

Using Arithmetic Operation it just can swap int or float type data.


But if we use Bitwise operation it can swap both number and string.



But it cannot swap any array, class; But if we use List it can swap everything. It can swap number, string, array and also can swap a class 

Array swap sample :
 'one');
 $y = array('b' =&gt; 'two');

 list($x,$y) = array($y,$x);

 echo 'X : ';
 print_r($x);
 echo 'Y : ';
 print_r($y);
?&gt;

Output:
X :
Array
(
    [b] =&gt; two
)
Y :
Array
(
    [a] =&gt; one
)


Class swap :
&lt;?php

    class a
    {
        public $name = 'alu';
    }
    class b
    {
        public $name = 'begun';
    }

   $x = new a();
   $y = new b();

   list($x,$y) = array($y,$x);

   echo 'X : ';
   var_dump($x);
   echo 'Y : ';
   var_dump($y);
?&gt;

so list is better ... :)</description>
		<content:encoded><![CDATA[<p>Thanks for the post.. i just want to add more&#8230;</p>
<p>Using Arithmetic Operation it just can swap int or float type data.</p>
<p>But if we use Bitwise operation it can swap both number and string.</p>
<p>But it cannot swap any array, class; But if we use List it can swap everything. It can swap number, string, array and also can swap a class </p>
<p>Array swap sample :<br />
 &#8216;one&#8217;);<br />
 $y = array(&#8217;b&#8217; =&gt; &#8216;two&#8217;);</p>
<p> list($x,$y) = array($y,$x);</p>
<p> echo &#8216;X : &#8216;;<br />
 print_r($x);<br />
 echo &#8216;Y : &#8216;;<br />
 print_r($y);<br />
?&gt;</p>
<p>Output:<br />
X :<br />
Array<br />
(<br />
    [b] =&gt; two<br />
)<br />
Y :<br />
Array<br />
(<br />
    [a] =&gt; one<br />
)</p>
<p>Class swap :<br />
&lt;?php</p>
<p>    class a<br />
    {<br />
        public $name = &#8216;alu&#8217;;<br />
    }<br />
    class b<br />
    {<br />
        public $name = &#8216;begun&#8217;;<br />
    }</p>
<p>   $x = new a();<br />
   $y = new b();</p>
<p>   list($x,$y) = array($y,$x);</p>
<p>   echo &#8216;X : &#8216;;<br />
   var_dump($x);<br />
   echo &#8216;Y : &#8216;;<br />
   var_dump($y);<br />
?&gt;</p>
<p>so list is better &#8230; <img src='http://www.mizanurrahman.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mizan</title>
		<link>http://www.mizanurrahman.com/2008/07/30/how-to-swap-values-of-two-variables-without-using-a-third-variable/comment-page-1/#comment-762</link>
		<dc:creator>mizan</dc:creator>
		<pubDate>Tue, 09 Dec 2008 12:54:34 +0000</pubDate>
		<guid isPermaLink="false">http://booleandreams.wordpress.com/?p=66#comment-762</guid>
		<description>Hi Shuvo
For developers who earn their living writing codes, these type of questions are very common. we have to face so many different type of questions which are outside of our interest. I completely agree with you that interview should assess only person's interest and skills but in programming basic is also very important and this question is a basic one ;)</description>
		<content:encoded><![CDATA[<p>Hi Shuvo<br />
For developers who earn their living writing codes, these type of questions are very common. we have to face so many different type of questions which are outside of our interest. I completely agree with you that interview should assess only person&#8217;s interest and skills but in programming basic is also very important and this question is a basic one <img src='http://www.mizanurrahman.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shuvo</title>
		<link>http://www.mizanurrahman.com/2008/07/30/how-to-swap-values-of-two-variables-without-using-a-third-variable/comment-page-1/#comment-761</link>
		<dc:creator>Shuvo</dc:creator>
		<pubDate>Tue, 09 Dec 2008 12:13:41 +0000</pubDate>
		<guid isPermaLink="false">http://booleandreams.wordpress.com/?p=66#comment-761</guid>
		<description>A cunning question to be asked in an interview. Are you familiar with something called 'Principle of least astonishment'? In any job interview, I believe, an interviewer should only assess a person's interest and skills. By the way, I am aware of this trick since 2000/2001 and I don't earn my living writing code.</description>
		<content:encoded><![CDATA[<p>A cunning question to be asked in an interview. Are you familiar with something called &#8216;Principle of least astonishment&#8217;? In any job interview, I believe, an interviewer should only assess a person&#8217;s interest and skills. By the way, I am aware of this trick since 2000/2001 and I don&#8217;t earn my living writing code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fawaad Rafique</title>
		<link>http://www.mizanurrahman.com/2008/07/30/how-to-swap-values-of-two-variables-without-using-a-third-variable/comment-page-1/#comment-756</link>
		<dc:creator>Fawaad Rafique</dc:creator>
		<pubDate>Tue, 25 Nov 2008 11:03:59 +0000</pubDate>
		<guid isPermaLink="false">http://booleandreams.wordpress.com/?p=66#comment-756</guid>
		<description>Thanks Mizan this is really a nice stuff for the begginers like me.</description>
		<content:encoded><![CDATA[<p>Thanks Mizan this is really a nice stuff for the begginers like me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: boes</title>
		<link>http://www.mizanurrahman.com/2008/07/30/how-to-swap-values-of-two-variables-without-using-a-third-variable/comment-page-1/#comment-763</link>
		<dc:creator>boes</dc:creator>
		<pubDate>Wed, 12 Nov 2008 09:00:12 +0000</pubDate>
		<guid isPermaLink="false">http://booleandreams.wordpress.com/?p=66#comment-763</guid>
		<description>i was asked this very same question on a test before. back then i had no idea how to do.
thanx</description>
		<content:encoded><![CDATA[<p>i was asked this very same question on a test before. back then i had no idea how to do.<br />
thanx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lavluda</title>
		<link>http://www.mizanurrahman.com/2008/07/30/how-to-swap-values-of-two-variables-without-using-a-third-variable/comment-page-1/#comment-754</link>
		<dc:creator>lavluda</dc:creator>
		<pubDate>Mon, 11 Aug 2008 15:54:26 +0000</pubDate>
		<guid isPermaLink="false">http://booleandreams.wordpress.com/?p=66#comment-754</guid>
		<description>thanks boss, nice post. Cool tricks, may be on next interview i may need this.</description>
		<content:encoded><![CDATA[<p>thanks boss, nice post. Cool tricks, may be on next interview i may need this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: booleandreams</title>
		<link>http://www.mizanurrahman.com/2008/07/30/how-to-swap-values-of-two-variables-without-using-a-third-variable/comment-page-1/#comment-753</link>
		<dc:creator>booleandreams</dc:creator>
		<pubDate>Mon, 11 Aug 2008 11:59:51 +0000</pubDate>
		<guid isPermaLink="false">http://booleandreams.wordpress.com/?p=66#comment-753</guid>
		<description>:) thanks boss.</description>
		<content:encoded><![CDATA[<p> <img src='http://www.mizanurrahman.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> thanks boss.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hasin</title>
		<link>http://www.mizanurrahman.com/2008/07/30/how-to-swap-values-of-two-variables-without-using-a-third-variable/comment-page-1/#comment-747</link>
		<dc:creator>hasin</dc:creator>
		<pubDate>Sat, 09 Aug 2008 20:13:36 +0000</pubDate>
		<guid isPermaLink="false">http://booleandreams.wordpress.com/?p=66#comment-747</guid>
		<description>here's another one

list($a, $b) = array($b, $a)

it will also swap values of two variables without using a third one :) - the php way!</description>
		<content:encoded><![CDATA[<p>here&#8217;s another one</p>
<p>list($a, $b) = array($b, $a)</p>
<p>it will also swap values of two variables without using a third one <img src='http://www.mizanurrahman.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> - the php way!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
