3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by elanorejoseph
0

hi
you can swap a,b like

$a=5;
$b=7;
echo "befor swaping value"."a=".$a."b=".$b;
$a=$a+$b;//$a=12
$b=$a-$b//12-7 so $b hold 5
$a=$a-$b//12-5 so $a hold 7
echo "after swaping value"."a=".$a."$b=".$b;

i hope you can understand my logic

Thanks

0

hi
you can swap a,b like

$a=5;
$b=7;
echo "befor swaping value"."a=".$a."b=".$b;
$a=$a+$b;//$a=12
$b=$a-$b//12-7 so $b hold 5
$a=$a-$b//12-5 so $a hold 7
echo "after swaping value"."a=".$a."$b=".$b;

i hope you can understand my logic

Thanks

Thanks buddy.. i understood your logic :)

0

in javascript it would be done this way if someone would like to translate it to php

var a="bob";
var b="joe";

a=[a,b];b=a[0];a=a[1];

enjoy! :)

0
var a="bob";
var b="joe";

a=[a,b];b=a[0];a=a[1];

that should do it! :)

ya that too worked. and i think using this we can swap two strings too
THANK YOU :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.