Q. Which keyword is used to define a function in PHP?

  • (A) def
  • (B) fun
  • (C) func
  • (D) function
πŸ’¬ Discuss
βœ… Correct Answer: (D) function

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

Code:
<?php declare(strict_types = 1);

function details(string $name, int $age){
    echo "Name: $name, Age: $age";
}
details("Alvin", "21");
?>
  • (A) Name: Alvin, Age: 21
  • (B) Name: Alvin, Age:
  • (C) Name: Alvin, Age: 0
  • (D) Fatal Error
πŸ’¬ Discuss
βœ… Correct Answer: (D) Fatal Error

Q. Which is the correct syntax of defining a default argument value in PHP?

  • (A) function function_name(type $argument_name : value) { /* function body*/ }
  • (B) function function_name(type $argument_name , value) { /* function body*/ }
  • (C) function function_name(type $argument_name = value) { /* function body*/ }
  • (D) All of the above
πŸ’¬ Discuss
βœ… Correct Answer: (C) function function_name(type $argument_name = value) { /* function body*/ }

Q. Which is the correct syntax of defining function return type in PHP?

  • (A) function function_name(type $arguments) : return_type { /* function body*/ }
  • (B) function function_name(type $arguments) , return_type { /* function body*/ }
  • (C) return_type function function_name(type $arguments) { /* function body*/ }
  • (D) function return_type function_name(type $arguments) { /* function body*/ }
πŸ’¬ Discuss
βœ… Correct Answer: (A) function function_name(type $arguments) : return_type { /* function body*/ }

Q. Which PHP function is used to create an array?

  • (A) array()
  • (B) arr()
  • (C) new_array()
  • (D) array
πŸ’¬ Discuss
βœ… Correct Answer: (A) array()

Q. How many types of arrays are there in PHP?

  • (A) 1
  • (B) 2
  • (C) 3
  • (D) 4
πŸ’¬ Discuss
βœ… Correct Answer: (C) 3

Q. Which is/are valid types of arrays in PHP?

  • (A) Indexed arrays
  • (B) Associative arrays
  • (C) Multidimensional arrays
  • (D) All of the above
πŸ’¬ Discuss
βœ… Correct Answer: (D) All of the above

Q. What is the difference between Indexed array and Associative array in PHP?

  • (A) Index array has numeric index while associative array has named keys
  • (B) Index array has numeric index while associative array has named keys and numeric index both
  • (C) Index array is one-dimensional array with numeric index while associative array is two-dimensional array with numeric index
  • (D) Index array has numeric index while associative array has one or more arrays
πŸ’¬ Discuss
βœ… Correct Answer: (A) Index array has numeric index while associative array has named keys

Q. Which is the correct example of an Indexed array in PHP?

  • (A) $cities = array("Delhi"; "Mumbai"; "Banglore");
  • (B) $cities = array("Delhi", "Mumbai", "Banglore");
  • (C) $cities = new array("Delhi", "Mumbai", "Banglore");
  • (D) $cities = new array(3) ("Delhi", "Mumbai", "Banglore");
πŸ’¬ Discuss
βœ… Correct Answer: (B) $cities = array("Delhi", "Mumbai", "Banglore");

Q. 111. Which is the correct example of an Associative array in PHP?

  • (A) $person = array("Alvin"=>"Delhi", "Alex"=>"Mumbai", "Bhavik"=>"Banglore");
  • (B) $person = array("Alvin"=>"Delhi"; "Alex"=>"Mumbai"; "Bhavik"=>"Banglore");
  • (C) $person = new array("Alvin"=>"Delhi", "Alex"=>"Mumbai", "Bhavik"=>"Banglore");
  • (D) $person = new array("Alvin"=>"Delhi"; "Alex"=>"Mumbai"; "Bhavik"=>"Banglore");
πŸ’¬ Discuss
βœ… Correct Answer: (A) $person = array("Alvin"=>"Delhi", "Alex"=>"Mumbai", "Bhavik"=>"Banglore");