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

  • (A) local scope
  • (B) global scope
  • (C) Either A or B
  • (D) None of these
πŸ’¬ Discuss
βœ… Correct Answer: (B) global scope

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
πŸ’¬ Discuss
βœ… Correct Answer: (C) Result

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
πŸ’¬ Discuss
βœ… Correct Answer: (A) Result1: 5 , Result2:

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

  • (A) php_ global
  • (B) global
  • (C) global_variable
  • (D) globalscope
πŸ’¬ Discuss
βœ… Correct Answer: (B) global

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;
πŸ’¬ Discuss
βœ… Correct Answer: (A) global $a, $b;

Q. What is the name of an array that stores all global variables in PHP?

  • (A) $GLOBAL[]
  • (B) $global[]
  • (C) $GLOBALS[]
  • (D) $PHP_GLOBALS[]
πŸ’¬ Discuss
βœ… Correct Answer: (C) $GLOBALS[]

Q. In the syntax of $GLOBALS[index], what does "index" hold?

  • (A) Index (starting from 0) of the variable
  • (B) Index (starting from 1) of the variable
  • (C) Name of the variable
  • (D) Line number of the variable where the variable was declared
πŸ’¬ Discuss
βœ… Correct Answer: (C) Name of the variable

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

Code:
<?php
function Increment(){
    static $num = 0;
    echo "$num";
    $num++;
}

Increment();
Increment();
Increment();
?>
  • (A) 000
  • (B) 111
  • (C) 011
  • (D) 012
πŸ’¬ Discuss
βœ… Correct Answer: (D) 012

Q. Which statement is faster echo or print?

  • (A) echo
  • (B) print
  • (C) either A or B
  • (D) None of these
πŸ’¬ Discuss
βœ… Correct Answer: (A) echo

Q. What is the correct syntax of echo statement in PHP?

  • (A) echo
  • (B) echo()
  • (C) echo = ()
  • (D) Both A and B.
πŸ’¬ Discuss
βœ… Correct Answer: (D) Both A and B.