PHP MCQs with answers Page - 20

Here, you will find a collection of MCQ questions on PHP. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 831.35K Points
Coach

Q. Which sign is used to declare variables in PHP?

  • (A) @
  • (B) &
  • (C) $
  • (D) _

A

Admin • 831.35K Points
Coach

Q. Which is not a valid variable name in PHP?

  • (A) age
  • (B) _age
  • (C) PersonAge
  • (D) 1age

A

Admin • 831.35K Points
Coach

Q. Which statement is commonly used for PHP output?

  • (A) write
  • (B) php.write
  • (C) log
  • (D) echo

A

Admin • 831.35K Points
Coach

Q. How many variable scopes are there in PHP?

  • (A) 1
  • (B) 2
  • (C) 3
  • (D) 4

A

Admin • 831.35K Points
Coach

Q. Which is not a valid variable scope in PHP?

  • (A) local
  • (B) global
  • (C) static
  • (D) external

A

Admin • 831.35K Points
Coach

Q. A variable declared outside a function has a ____.

  • (A) local scope
  • (B) global scope
  • (C) Either A or B
  • (D) None of these

A

Admin • 831.35K Points
Coach

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

Code:
<?php
$x = 5;

function myFunction(){
    echo "Result $x";
}
myFunction();
?>
  • (A) Result $x
  • (B) Result 5
  • (C) Result
  • (D) None of the above

A

Admin • 831.35K Points
Coach

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

Code:
<?php
function myFunction()
{
    $x = 5;
    echo "Result1: $x , ";
}
myFunction();
echo "Result2: $x";
?>
  • (A) Result1: 5 , Result2:
  • (B) Result1: 5 , Result2: 0
  • (C) Result1: 5 , Result2: 5
  • (D) None of the above

A

Admin • 831.35K Points
Coach

Q. Which PHP keyword is used to access a global variable inside the function?

  • (A) php_ global
  • (B) global
  • (C) global_variable
  • (D) globalscope

A

Admin • 831.35K Points
Coach

Q. There are two variables a, b which declared in global scope, which is the correct PHP statement to access them within a function?

  • (A) global $a, $b;
  • (B) global $a $b;
  • (C) global ($a, $b);
  • (D) php_global $a, $b;

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ