PHP Programs

Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 50: Write a program to swap two string variables without using third or temp variable.

swap.php

<!DOCTYPE html>  
<html>  
<head>	
	<title>PHP Programs TutorialDuniya.com</title>
</head>
<body>  
	<?php  
		$string1 = " TUTORIALS ";  
		$string2 = " DUNIYA ";  

		echo "Strings before swapping: " . $string1 . " " . $string2;  

		$string1 = $string1 . $string2;  

		$string2 = substr($string1, 0, (strlen($string1) - strlen($string2)));  
		
		$string1 = substr($string1, strlen($string2));  
		
		echo "<br>Strings after swapping: " . $string1 . " " . $string2;  
	?>  
</body>  
</html>



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.