Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
16 views7 pages

WT

The document consists of a series of multiple-choice questions related to PHP programming concepts, covering topics such as arrays, functions, file handling, and variable types. Each question presents four options, with the goal of testing knowledge on PHP syntax and functionality. The questions range from basic to intermediate levels, making it suitable for learners and developers looking to assess their understanding of PHP.

Uploaded by

aarnav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

WT

The document consists of a series of multiple-choice questions related to PHP programming concepts, covering topics such as arrays, functions, file handling, and variable types. Each question presents four options, with the goal of testing knowledge on PHP syntax and functionality. The questions range from basic to intermediate levels, making it suitable for learners and developers looking to assess their understanding of PHP.

Uploaded by

aarnav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

WT

1. Which of the following is an array type in PHP? a) Indexed array


b) Associative array
c) Multidimensional array
d) All of the above

2. How do you declare an indexed array in PHP? a) $arr = array(1, 2, 3);


b) $arr[] = array(1, 2, 3);
c) $arr = [1, 2, 3];
d) All of the above

3. What is the correct way to access the 3rd element of an indexed array $arr = [1, 2, 3, 4, 5]; in
PHP? a) $arr[3]
b) $arr[2]
c) $arr[4]
d) $arr[5]

4. In PHP, which function is used to get the length of an array? a) count()


b) length()
c) size()
d) array_length()

5. Which of the following can be stored in a multidimensional array? a) Integer values only
b) Strings only
c) Arrays
d) Only associative arrays

6. How do you define an associative array in PHP? a) $arr = array("key1" => "value1", "key2" =>
"value2");
b) $arr = array("value1", "value2", "value3");
c) $arr = [1, 2, 3];
d) $arr = array(1, 2, 3);

7. What does array_push() function do in PHP? a) Adds an element to the end of an array
b) Adds an element to the beginning of an array
c) Removes an element from the array
d) Reverses the array

8. How would you declare a 2D array in PHP? a) $arr = [ [1, 2], [3, 4], [5, 6]];
b) $arr = array(1, 2, 3, 4);
c) $arr = [1, [2, 3], 4];
d) $arr = array("row1" => 1, "row2" => 2);

9. Which PHP function is used to combine two arrays? a) merge()


b) concat()
c) array_merge()
d) append_array()
10. How can you access an element in a multidimensional array $arr = array(array(1, 2), array(3,
4));? a) $arr[0,1]
b) $arr[1,0]
c) $arr[0][1]
d) $arr[1][1]

11. How do you declare a simple function in PHP? a) function myFunction() { }


b) function myFunction[] { }
c) func myFunction() { }
d) function myFunction() { return value; }

12. Which keyword is used to return a value from a function in PHP? a) return
b) yield
c) output
d) result

13. What is the purpose of the include statement in PHP? a) To include a file inside a function
b) To include an external PHP file into the current script
c) To include only classes
d) To include variables in the function

14. Which of the following is the correct way to define a function that takes two parameters in
PHP? a) function myFunction($a, $b) { }
b) function myFunction($a & $b) { }
c) function myFunction($a | $b) { }
d) function myFunction($a, $b = 10) { }

15. Which function is used to pass arguments by reference to a function in PHP? a)


pass_by_ref()
b) & (ampersand sign)
c) ref()
d) func_ref()

16. What is the default return type of a PHP function? a) String


b) Integer
c) Boolean
d) None (void)

17. Can a PHP function return multiple values? a) Yes, by returning an array
b) No, a function can only return one value
c) Yes, by using references
d) No, PHP does not allow multiple returns

18. What happens if you call a function before its declaration in PHP? a) It results in a fatal error
b) It works if the function is declared later in the file
c) It results in a warning only
d) The function call is ignored
19. Which of the following is the correct way to define a function with a default value for a
parameter? a) function myFunction($a = 10) { }
b) function myFunction($a : 10) { }
c) function myFunction($a[10]) { }
d) function myFunction($a ==> 10) { }

20. What does the global keyword do in PHP functions? a) It allows a variable to be used within
a function
b) It makes a function available globally
c) It can be used to access global variables from within a function
d) It prevents a function from being used in other scripts

21. Which function is used to remove the last element of an array in PHP? a) array_pop()
b) array_shift()
c) array_remove()
d) pop_array()

22. Which function would you use to sort an indexed array in ascending order in PHP? a) sort()
b) rsort()
c) ksort()
d) asort()

23. What is the correct way to declare an array with string keys in PHP? a) $arr = array("key1" =>
"value1", "key2" => "value2");
b) $arr = ["value1", "value2"];
c) $arr = array(1 => "value1", 2 => "value2");
d) $arr = array("value1", "value2");

24. Which of the following functions can be used to check if a variable is an array? a) is_array()
b) array_check()
c) check_array()
d) is_arraytype()

25. How do you access the value "John" in the following associative array: $arr =
array("first_name" => "John", "last_name" => "Doe");? a) $arr["first_name"]
b) $arr["John"]
c) $arr[0]
d) $arr[first_name]

26. In PHP, which function can be used to reverse the order of elements in an array? a) reverse()
b) array_reverse()
c) sort_reverse()
d) array_flip()

27. What does the array_keys() function do in PHP? a) Returns all the values of an array
b) Returns all the keys of an array
c) Returns the first key of an array
d) Returns the last key of an array
28. Which function is used to remove a specific element from an array in PHP? a) unset()
b) array_remove()
c) remove()
d) array_shift()

29. What will count(array()) return in PHP? a) 0


b) 1
c) NULL
d) Error

30. Which of the following is the correct way to check if an array is empty in PHP? a)
is_empty($arr)
b) empty($arr)
c) array_empty($arr)
d) isset($arr)

31. What is the result of using array_merge() on two arrays in PHP? a) Combines the arrays and
removes duplicates
b) Combines the arrays and keeps duplicates
c) Combines the arrays and sorts them
d) Merges arrays but drops all the keys

32. Which of the following is used to find the value of a key in an array in PHP? a) array_find()
b) array_key_exists()
c) array_search()
d) array_value_exists()

33. How do you declare a two-dimensional array in PHP? a) $arr = array(1, 2, 3, 4);
b) $arr = array(array(1, 2), array(3, 4));
c) $arr = array(1 => "a", 2 => "b");
d) $arr = [1, [2, 3], 4];

34. What is the default behavior of the array_merge() function if two arrays have the same key?
a) It will overwrite the value of the duplicate key
b) It will combine both values into one
c) It will return an error
d) It will ignore the second array

35. Which function is used to get all the values in an array in PHP? a) array_values()
b) array_items()
c) get_values()
d) all_values()

36. What does the array_shift() function do in PHP? a) Removes the first element of an array
b) Adds an element to the beginning of an array
c) Sorts the array in ascending order
d) Shifts the array to the right
37. How do you create a constant array in PHP? a) define("MY_ARRAY", [1, 2, 3]);
b) constant("MY_ARRAY", [1, 2, 3]);
c) array_define("MY_ARRAY", [1, 2, 3]);
d) const MY_ARRAY = [1, 2, 3];

38. What is the return type of the array_slice() function in PHP? a) A string
b) A new array
c) A boolean
d) A number

39. What is the correct way to pass an array to a function in PHP? a) function myFunction($arr)
b) function myFunction(&$arr)
c) Both a and b
d) Neither a nor b

40. How can you check if a key exists in an associative array in PHP? a) isset()
b) exists()
c) key_exists()
d) array_key()

41. What does PHP stand for? a) Personal Home Page


b) PHP Hypertext Processor
c) Preprocessor Hypertext Pages
d) Private Home Pages

42. PHP code is executed on the: a) Client-side


b) Server-side
c) Both client-side and server-side
d) Neither client-side nor server-side

43. Which of the following is the correct way to start a PHP script? a)
b)
c)
d)

44. How do you output "Hello, World!" in PHP? a) print("Hello, World!");


b) echo "Hello, World!";
c) printf("Hello, World!");
d) All of the above

45. Which symbol is used to indicate a variable in PHP? a) $


b) @
c) #
d) &

46. Which of the following is the correct way to comment a line in PHP? a) // This is a comment
b) /* This is a comment */
c) # This is a comment
d) All of the above

47. In PHP, what does the echo statement do? a) It outputs data to the screen
b) It executes a script
c) It returns a value from a function
d) It includes another file

48. Which function is used to check the type of a variable in PHP? a) is_type()
b) gettype()
c) checktype()
d) typecheck()

49. What is the extension of a PHP file? a) .html


b) .php
c) .php3
d) .phtml

50. Which of the following statements is used to terminate a script in PHP? a) exit()
b) stop()
c) terminate()
d) break()

51. What does the phpinfo() function do? a) Outputs all the information about PHP's
configuration
b) Executes PHP code
c) Displays current memory usage
d) Executes a specific function

52. What is the correct way to include a file in PHP? a) include("file.php");


b) require("file.php");
c) Both a and b
d) None of the above

53. How do you declare a constant in PHP? a) define("MY_CONSTANT", "value");


b) constant("MY_CONSTANT", "value");
c) const MY_CONSTANT = "value";
d) Both a and c

54. Which function is used to check whether a file exists in PHP? a) file_exists()
b) is_file()
c) check_file()
d) file_check()

55. How do you concatenate two strings in PHP? a) str_concat("Hello", "World");


b) "Hello" + "World";
c) "Hello" . "World";
d) concatenate("Hello", "World");
56. How do you include a PHP file from another PHP file? a) include('file.php');
b) insert('file.php');
c) require('file.php');
d) Both a and c

57. What is the correct way to create an array in PHP? a) $arr = (1, 2, 3);
b) $arr = [1, 2, 3];
c) $arr = array(1, 2, 3);
d) Both b and c

58. Which of the following can PHP run on? a) Windows


b) Linux
c) macOS
d) All of the above

59. Which of the following is not a valid PHP operator? a) =


b) ==
c) ===
d) !===

60. What is the purpose of the isset() function in PHP? a) To check if a variable is declared and
not null
b) To check if a variable is null
c) To check if a variable is set
d) To check if a variable exists

You might also like