ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Scripts  >>  PHP
 
 


 

 
 PHP interview questions  PHP Interview Questions
 ASP interview questions  ASP Interview Questions
 CGI Perl interview questions  CGI Perl Interview Questions
 JavaScript interview questions  JavaScript Interview Questions
 VB Script interview questions  VB Script Interview Questions
 JSP interview questions  JSP Interview Questions
 Shell Script interview questions  Shell Script Interview Questions
 Python interview questions  Python Interview Questions
 Tcl interview questions  Tcl Interview Questions
 Awk interview questions  Awk Interview Questions
 AJAX interview questions  AJAX Interview Questions
 Ruby on Rails interview questions  Ruby on Rails Interview Questions
 Scripts AllOther interview questions  Scripts AllOther Interview Questions
Question
1. Write a function to swap two values ?
$a = 10;
$b = 20;
echo $a, $b;
swap(); // If u want u can pass parameters
echo $a, $b; // It should print 20 , 10
 Question Submitted By :: Binoyav
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 1. Write a function to swap two values ? $a = 10; $b = 20; echo $a, $b; swap(); // If u want u can pass parameters echo $a, $b; // It should print 20 , 10
Answer
# 1
function swap(){

$a = 10;
$b = 20;

$a = $a + $b;
$b = $a - $b;
$a = $a - $b;
echo $a, $b;

}
 
Is This Answer Correct ?    1 Yes 1 No
Ranjan
 
  Re: 1. Write a function to swap two values ? $a = 10; $b = 20; echo $a, $b; swap(); // If u want u can pass parameters echo $a, $b; // It should print 20 , 10
Answer
# 2
The above answer is correct. But the interviewer does not
want to echo the values from inside the function. It should
be in the following way
$a = 10;
$b = 20;
echo $a, $b;
swap(); // Here if you want you can pass the variables
echo $a, $b;

function swap()
{
}
 
Is This Answer Correct ?    1 Yes 0 No
Binoyav
 
 
 
  Re: 1. Write a function to swap two values ? $a = 10; $b = 20; echo $a, $b; swap(); // If u want u can pass parameters echo $a, $b; // It should print 20 , 10
Answer
# 3
$a = 10;
	$b = 20;
	
	echo $a, $b;
	echo "<br>";
	swap($a, $b);
	echo $a, $b;
	function swap(&$a, &$b)
	{
		$temp = $a;
		$a = $b;
		$b = $temp;
	}
 
Is This Answer Correct ?    7 Yes 0 No
Binoyav
 
  Re: 1. Write a function to swap two values ? $a = 10; $b = 20; echo $a, $b; swap(); // If u want u can pass parameters echo $a, $b; // It should print 20 , 10
Answer
# 4
One way is:

function swap($x, $y) {
    $x ^= $y ^= $x ^= $y;
    return array($x,$y);
}
 
Is This Answer Correct ?    1 Yes 0 No
Ramse
 
  Re: 1. Write a function to swap two values ? $a = 10; $b = 20; echo $a, $b; swap(); // If u want u can pass parameters echo $a, $b; // It should print 20 , 10
Answer
# 5
<?php
$a=10;
$b=20;
echo $a,$b;
echo "<br>";
swap($a, $b);
echo "<br>";
echo $a,$b;
function swap(&$a, &$b)
{
  $a = $a + $b;
  $b = $a - $b;
  $a = $a - $b;
}
?>
 
Is This Answer Correct ?    4 Yes 0 No
Vivek Srivastava
 
  Re: 1. Write a function to swap two values ? $a = 10; $b = 20; echo $a, $b; swap(); // If u want u can pass parameters echo $a, $b; // It should print 20 , 10
Answer
# 6
yes we can do this also.
But pass by reference allow in PHP5 not in PHP4.
 
Is This Answer Correct ?    1 Yes 0 No
Ramse
 
  Re: 1. Write a function to swap two values ? $a = 10; $b = 20; echo $a, $b; swap(); // If u want u can pass parameters echo $a, $b; // It should print 20 , 10
Answer
# 7
$x=$a;
$a=$b;
$b=$x;
echo $a.",".$b;
 
Is This Answer Correct ?    0 Yes 0 No
Nikunj Kansara
 

 
 
 
Other PHP Interview Questions
 
  Question Asked @ Answers
 
How can post form values with out press submit button  5
How to get the DNS servers of a domain name? Life-Infotech1
Use of Session  4
What are the differences between procedure-oriented languages and object-oriented languages?  2
What are the different types of Errors in PHP? Troop-Software6
What is the difference between Joomla and Drupal? T3-Softwares2
What is the purpose of destructor ?  1
What is indexing in mysql and how do we create indexing in mysql  2
How are Variables Defined in PHP? T3-Softwares4
In how many ways we can retrieve the date in the result set of mysql using PHP?  1
How can i send a HTML file to mail account.  2
List out some tools through which we can draw E-R diagrams for mysql?  4
What is happening in the following code $objA = new A(); // A is a class $objB = $objA; NIIT1
what are the current or latest versions of LAMP ? Linux, Apache, MySql, PHP  1
What is the substitution of submit in PHP? RedAlkemi4
What is meant by nl2br()?  2
how to convert PHP code in to java code  2
What is indexing how many types? Net-Solution2
How do I add to the beginning of an array and find the number of elements in it? Rushmore-Consultancy1
what is the url rewriting?how to rewrite the url? give any example  1
 
For more PHP Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com