PHP is one of the most server site scripting language used all over the world. Today we are going to discuss the basic questionnaire for freshers. When you are going for interview these below questions and answers are must for every one. You can also enjoy free PDF to download with.
$_SERVER["REMOTE_ADDR"];
but there are many variables like proxies, server, client, system, current and public that may require specific changes.error_reporting(E_ALL); ini_set('display_errors', '1');
password_hash
and password_verify
which are respectively used as hashing and checking method. MD5 was used before but now has become obsolete.[table caption=”Difference between GET and POST Methods” width=”100%” colwidth=”50%|50%” colalign=”left|left”]
GET,POST
Data is being shown in the URL by this method after submitting the data., In this data is not shown in the URL.
It not good strategy to send sensitive data via GET method, We can send sensitive data by POST method.
It has limit of only 2kb data able to send for request, We can pass unlimited data by this method
[/table]
[table caption=”Difference between unlink and unset functions” width=”100%” colwidth=”50%|50%” colalign=”left|left”]
unlink() function deletes the given file from the file system., unset() function makes a variable undefined or unset a variable or you can say destroy a variable.
It returns True – when the operation complete successfully or false – if operation is not completed.,No value is returned in unset function.
[/table]
[table caption=”Difference between include() and require() statements” width=”100%” colwidth=”50%|50%” colalign=”left|left”]
It is used to include a file in php page with filename as its parameter., It is also used to include a file in php page with filename as its parameter.
It does not produce any error. But a WARNING is shown to the user and execution of the file continues.,It produce FATAL error if file is not found on specified path and halt the execution of script.
[/table]
[table caption=”Difference between include(), require() and require_once() statements” width=”100%” colwidth=”33%|33%|33%” colalign=”left|left|left”]
It is used to include a file in php page with filename as its parameter., It is also used to include a file in php page with filename as its parameter., It also includes a file but it evaluates a specific file only when if it has not been included before.
It does not produce any error. But a WARNING is shown to the user and execution of the file continues.,It produce FATAL error if file is not found on specified path and halt the execution of script.,It is used when you want to include a file which has lots of functions etc. and by using this statement will help in saving errors example “function already decared or re-declared”.
include(“filename.php”),require(“filename.php”),require_once(“filename.php”);
[/table]
<html> <body> <h2>PHP Script to find Prime number or not!</h2> <form method="post" action-xhr="#"> Enter a number: <input type="number" name="number" min="0" /> <input type="submit" value="Find Prime Number" name="Submit" /> </form> </body> </html> <?php //here is the function to find prime number //this function return true if the number is prime function GetPrime($number) { $res = false; $i = $c = 0; for ($i = 1; $i <= $number; $i++) { //loop till $i equals to $num if ($number % $i == 0) { $c++; //increment the value of $c } } //if the value of $c is 2 then it is a prime number //because a prime number should be exactly divisible by 2 times only (itself and 1) if ($c == 2) { $res = true; } return $res; } if (isset($_POST['Submit']) && $_POST['Submit']) { $number = $_POST['number']; $primenumber = GetPrime($number); if ($primenumber) { print "<b>" . $number . "</b> is a Prime number."; } else { print "<b>" . $number . "</b> is not a Prime number."; } } ?>
<html> <body> <h2>Leap Year Program</h2> <form action-xhr="#" method="post"> <input type="text" name="year" placeholder="Enter Year Here" /> <input type="submit" name="submit" /> </form> </body> </html> <?php if( $_POST ) { //get the year $year = $_POST[ 'year' ]; //check if entered value is a number if(!is_numeric($year)) { echo "Strings not allowed, Input should be a number"; return; } //multiple conditions to check the leap year if( (0 == $year % 4) and (0 != $year % 100) or (0 == $year % 400) ) { echo "$year is a leap year"; } else { echo "$year is not a leap year"; } } ?>
<?php $num = 0; $a = 0; $b = 1; echo "<h3>Fibonacci series for first 10 numbers: </h3>"; echo $a.' '.$b.' '; while ($num < 8 ) { $c = $a + $b; echo $c.' '; $a = $b; $b = $c; $num = $num +1; } ?>
Initializing first and second number as 0 and 1.it will print first and second number. start our loop. So third number will be the sum of the first two numbers.
<?php $i=1; for($j=5;$j>=1;$j--) { echo str_repeat(" ",$j-1); echo str_repeat('*',$i++); echo "<br />"; } ?>
<?php $num = 5; $factorial = 1; for ($i=$num; $i>=1; $i--) { $factorial = $factorial * $i; } echo "Result is $factorial"; ?> Result is 120.
<html> <head> <title>Find Largest Numbers in an Array </title> </head> <body> Enter the Numbers separated by Commas <br /> (eg: 10,20,30) <br /><br /> <form method="post" action-xhr="#"> <input type="text" name="number"/> <button type="submit">Check</button> </form> </body> </html> <?php if($_POST) { $number = $_POST['number']; $numArray = explode(',', $number); $largest = $numArray[0]; foreach($numArray as $num){ if($num > $largest){ $largest = $num; } } echo "Your Largest Number is: $largest <br />"; } ?>
<?php for ($i = 1; $i <= 10; $i++) { echo "The Number is: $i <br>"; } ?>
<?php $x = 1; while($x <= 10) { echo "The number is: $x <br>"; $x++; } ?>
<!Doctype html> <html> <body> <form action-xhr="#" method="post"> Enter a number: <input type="text" name="number" /> <input type="submit" value="Table" /> </form> <?php if($_POST){ $num=$_POST['number']; echo "Table of $num: <br>"; for($i=1;$i<=10;$i++) { $value=$num*$i; echo "$num*$i=$value<br>"; } } ?> </body> </html>
Q: What will be the values of $a and $b after the code below is executed? Explain your answer.?
Answer :
$a=’2′;
$b =&$a;
$b= “3$b”; //values get parse in double quotes
echo ‘$b is = ‘. $b;
echo ‘<br>$a is = ‘. $a;
Both $a and $b will be equal to the string “32” after the above code is executed.
Output will be :
$b is = 32
$a is = 32
Its because:
The statement $b = &$a;
sets $b
equal to a reference to $a
(as opposed to setting $b
to the then-current value of $a
). Thereafter, as long as $b
remains a reference to $a
, anything done to $a
will affect $b
and vice versa.
after executing the statement $b = "3$b"
, $b
is set equal to the string "3"
followed by the then-current value of $b
(which is the same as $a
) which is 2, so this results in $b
being set equal to the string "32"
(i.e., the concatenation of "3"
and "2"
). And, since $b
is a reference to $a
, this has the same affect on the value of $a
, so both end up equal to "32"
& (amperdsand) is used when we are using “Pass by Reference”.
References makes it possible for two variables to refer to the same content. In other words, a variable points to its content (rather than becoming that content). Passing by reference allows two variables to point to the same content under different names. The ampersand ( & ) is placed before the variable to be referenced.
Q: What will be the values of $a and $b after the code below is executed? Explain your answer.?
Answer :
$a=2;
$b =&$a;
echo ‘<br>after referencing $a = ‘.$b;
$b= ‘3$b’; //values does not get parsed in single quotes
echo ‘<br>’;
echo ‘$b is = ‘. $b;
echo ‘<br>$a is = ‘. $a;
after refrencing $a = 2
Both $a and $b will be equal to the string “3$b” after the above code is executed.
Output will be :
$b is = 3$b
$a is = 3$b
Also find out more Interview and Questions for getting regular information now!
When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…
In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…
In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…
In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…
When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…
In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…