My Report (&Account)

PHP Online Test


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)

Here is the complete list of test quizzes on PHP.

1. What will be the output of the following PHP code?

<?php
$a = "hello";
if (strlen($a))
    print strlen($a);
else
    print "hi";
?>

Question 1 of 50

2. What will be the output of the following PHP code?

<?php
$a = 10;
$b = 4;
$c = fun(10,4);
function fun($a,$b)
{
    $b = 3;
    return $a - $b + $b - $a; 
}
echo $a;
echo $b;
echo $c;
?>

Question 2 of 50

3. What will be the output of the following PHP code?

<?php
$x = 1;
if ($x = $x&0)
    print $x ;
else
    print "how are u";
?> 

Question 3 of 50

4. What will be the output of the following PHP code?

<?php
function time($string)
{
    echo strtr("Towe Pa55", "ow5", $string);
}
time("ims");
?>

Question 4 of 50

5. There are two objects-
$product1 = new Shop();
$product2 = new Shop();
Which one of the following statements is right about them?

Question 5 of 50

6. Since which version of PHP was the directive max_file_limit available.

Question 6 of 50

7. If you call a method and it doesn't exist it'll cause a problem. To check the method which function will you use?

Question 7 of 50

8. What will be the output of the following PHP code?

<?php
function sum($x, $y)
{
    $z = $x + $y;
    return $z;
}
echo "5 + 10 = " . sum(7,13) . "<br>";
echo "7 + 13 = " . sum(2,4) . "<br>";
echo "2 + 4 = " . sum(5,10);
?>

Question 8 of 50

9. ________ are used in class diagrams to describe the way in which specific elements should be used.

Question 9 of 50

10. Which one of the following PHP function is used to determine a file's last access time?

Question 10 of 50

11. What will be the output of the following PHP code?

<?php
function fun()
{
    static $x = 0;
    echo $x;
    $x++;
}
fun();
fun();
fun();
?>

Question 11 of 50

12. Which of the following statements causes PHP to disregard repeated error messages that occur within the same file and on the same line?

Question 12 of 50

13. What will be the output of the following PHP code?

    <?php
       echo "chr(52)";
    ?>

Question 13 of 50

14. The developers of PHP deprecated the safe mode feature as of which PHP version.

Question 14 of 50

15. Which version of PHP allows you to define constant properties within a class?

Question 15 of 50

16. What will be the output of the following PHP code?

<?php
$user = array("Ashley", "Bale", "Shrek", "Blank");
for ($x = 0; $x < count($user); $x) 
{
    if ($user[$x++] == "Shrek") 
	    continue;
    printf ($user[$x]); 
}
?>

Question 16 of 50

17. What will be the output of the following PHP code?

<?php
$x = 10;
$y = 20;
if ($x > $y && 1||1)
    print "hi" ;
else
    print "how are u";
?> 

Question 17 of 50

18. What will be the output of the following PHP code?

<?php
$names = array("Sam", "Bob", "Jack");
echo $names[0]." is the brother of ".$names[1]." and ".$names[1].".".$brother;
?>

Question 18 of 50

19. What will be the output of the following PHP code?

<?php
$a = 10; $b = 10;
if ($a = 5)
    $b--;
print $a;print $b--;
?>

Question 19 of 50

20. When you use the $_GET variable to collect data, the data is visible to ___________

Question 20 of 50

21. # is the visibility code for?

Question 21 of 50

22. What will be the output of the following PHP code?

    <?php
    $value = 'car';
    $result = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
    ?>

Question 22 of 50

23. Which one of the following is the right way to clone an object?

Question 23 of 50

24. What will be the output of the following PHP code?

<?php
echo 5 * 9 / 3 + 9
?>

Question 24 of 50

25. What will be the output of the following PHP code?

    <?php
    function calc($price, $tax="")
    {
        $total = $price + ($price * $tax);
        echo "$total"; 
    }
    calc(42);	
    ?>
        

Question 25 of 50

26. What will be the output of the following PHP code?

<?php
$y = 2;
if ($y-- == ++$y)
{
    echo $y;
}
?>

Question 26 of 50

27. Which one of the following preg PHP function is used to do a find and replace on a string or an array?

Question 27 of 50

28. Which function sets the file filename last-modified and last-accessed times?

Question 28 of 50

29. What will be the output of the following PHP code?

<?php
function constant()
{
    define("GREETING", "Welcome to Narnia",true);
    echo greeting;
}
?>

Question 29 of 50

30. What will be the output of the following PHP code?

    <?php
    function a()
    {
        function b()
        {
            echo 'I am b';
 	}
        echo 'I am a';
    }
    a();
    a();
    ?>
        

Question 30 of 50

31. What will be the output of the following PHP code?

    <?php
    $number = array(0,1,two,three,four,5);
    $num = preg_grep("/[0-5]/", $number);
    print_r($num);
    ?>
    

Question 31 of 50

32. Which version of PHP introduced the advanced concepts of OOP?

Question 32 of 50

33. Which one of the following function is used to send an email using PHP script?

Question 33 of 50

34. When a user confirms that he wishes to delete an entry, that entry's URL is passed to a function which removes the entry from the __________

Question 34 of 50

35. Which version of PHP introduced the concept called late static binding?

Question 35 of 50

36. What will be the output of the following PHP code?

<?php
$var1 = 3;
print ++$var++;
?>

Question 36 of 50

37. What will be the output of the following PHP code?

<?php
$a = "1";
$b = "0";
if ((int)$a && $b) 
    print"hi";
else 
    print "hello";
?>

Question 37 of 50

38. What will be the output of the following PHP code?

<?php
$cars = array("Volvo", "BMW", "Toyota");
echo "I like " . $cars[2] . ", " . $cars[1] . " and " . $cars[0] . ".";
?>

Question 38 of 50

39. Which keyword precedes a method name?

Question 39 of 50

40. How should we add a single line comment in our PHP code?

    i) /?
    ii) //
    iii) #
    iv) /* */

Question 40 of 50

41. What will be the output of the following PHP code?

<?php
$x = 0;
if ($x == 1)
    if ($x >= 0)
        print "true";
    else
        print "false"; 
?>

Question 41 of 50

42. What will be the output of the following PHP code?

<?php
echo "Hello world <strong>I am learning PHP</strong>"
?>

Question 42 of 50

43. Which superglobal stores a variety of information pertinent to a file uploaded to the server via a PHP script?

Question 43 of 50

44. What will be the output of the following PHP code?

<?php
$color = red;
echo "\$color";
?>

Question 44 of 50

45. What will be the output of the following PHP code?

<?php
class ShopProduct
{
    // Define properties
    public $title;
    public $firstName;
    public $lastName;
    public $price;

    // Constructor to initialize the properties
    public function __construct($title, $firstName, $lastName, $price)
    {
        $this->title = $title;
        $this->firstName = $firstName;
        $this->lastName = $lastName;
        $this->price = $price;
    }

    // Method to return the full name of the producer
    public function getProducer()
    {
        return "{$this->firstName} {$this->lastName}";
    }
}
// Existing classes and objects
class ShopProductWriter
{
    public function write($shopProduct)
    {
        $str = "{$shopProduct->title}: " . $shopProduct->getProducer() . " ({$shopProduct->price})\n";
        print $str;
    }
}
$product1 = new ShopProduct("My Antonia", "Willa", "Cather", 5.99);
$writer = new ShopProductWriter();
$writer->write($product1);
?>

Question 45 of 50

46. What will be the output of the following PHP code?

	
    <?php
    $arr = array ("picture1.JPG", "picture2.jpg",
    "Picture10.jpg", "picture20.jpg");
    sort($arr);
    print_r($arr);
    ?>

Question 46 of 50

47. What will be the output of the following PHP code?

<?php
$i = 2;
while (++$i)
{   
    while (--$i > 0)
        print $i;
}
?>

Question 47 of 50

48. What will be the output of the following PHP code?

<?php
$on$e = 1;
$tw$o = 2;
$thre$e = 3;
$fou$r = 4;
echo "$on$e / $tw$o + $thre$e / $fou$r"; 
?>

Question 48 of 50

49. Which version introduced the function error_get_last()?

Question 49 of 50

50. What will be the output of the following PHP code?

    <?php
    function convertSpace($string)
    {
        return str_replace("_", " ", $string);
    }
    $string = "Peter_is_a_great_guy!";
    echo filter_var($string, FILTER_CALLBACK, array("options"=>"convertSpace"));
    ?>

Question 50 of 50


 

Topic wise Test Quizzes on PHP

PHP tests, quizzes, and exams are great ways to learn and test your PHP programming skills. Whether you’re a beginner or experienced, challenge and boost your confidence with our engaging online quizzes on PHP Basics, Array, Loops, OOP, String, Database, Object, if else Statement, Operators, Function, and Advanced PHP. Start the PHP online test now!



PHP Programming Certification Test

PHP Programming Certification Test is a free certification exam. However, you need to score an A grade in each of the "Certification Level Tests 1 to 10" to be eligible to take part in this certification test. So, take all the "10 Tests" starting from Certification Level 1 upto Level 10, before taking the final Certification test.


Level 1 to 10 Tests:
Total Questions: 25, Total Time: 30 min, Correct Answer: 2 points, Wrong Answer: -1 point

Certification Test:
Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

PHP Programming Internship Test

If you scored either Grade A* or Grade A in our PHP Programming Internship Test, then you can apply for Internship at Sanfoundry in PHP Programming.


Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

PHP Programming Job Test

It is designed to test and improve your skills for a successful career, as well as to apply for jobs.


Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

Note: Before you get started on these series of online tests, you should practice our collection of 1000 MCQs on PHP Programming .

Sanfoundry Scoring & Grading System

Sanfoundry tests and quizzes are designed to provide a real-time online exam experience. Here is what you need to know about them.

  • Scoring System: You get 2 points for each correct answer but lose 1 point for every wrong answer.
  • Grading System: Your grade depends on your final score and can be one of the following:

    • Grade A* - Genius (100%)
    • Grade A - Excellent (80% to 99%)
    • Grade B - Good (60% to 80%)
    • Grade C - Average (40% to 60%)
    • Grade D - Poor (0% to 40%)
advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.