0% found this document useful (0 votes)
38 views

Phpcopy Code: Array Echo Isset

The document provides answers to 55 questions about PHP functions and concepts. It covers topics like arrays, strings, sessions, MySQL, and more. Multiple choice answers are provided for questions about PHP functions, operators, and syntax.

Uploaded by

ABDUL SAMAD
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Phpcopy Code: Array Echo Isset

The document provides answers to 55 questions about PHP functions and concepts. It covers topics like arrays, strings, sessions, MySQL, and more. Multiple choice answers are provided for questions about PHP functions, operators, and syntax.

Uploaded by

ABDUL SAMAD
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

1.

Which of the following functions checks if a PHP variable has a


value and is not NULL? a) isset() b) empty() c) is_value() d) notnull()

Answer: a) isset()

2. Which PHP function can be used to get the length of a string?


a) strlen() b) strlength() c) length() d) sizeof()

Answer: a) strlen()

3. What will the following code return?

phpCopy code
$fruit = array ( 'a' => 'apple' , 'b' => 'banana' ); echo isset ( $fruit [ 'c' ]);

a) apple b) banana c) 1 d) Nothing (it will not display any output)

Answer: d) Nothing (it will not display any output)

4. Which of the following functions will return a string in all


uppercase? a) to_uppercase() b) strtoupper() c) strup() d) upcase()

Answer: b) strtoupper()

5. What is the purpose of the in_array() function in PHP? a) Checks


if a value exists in an array b) Inserts a value into an array c) Checks if
an array is inside another array d) None of the above

Answer: a) Checks if a value exists in an array

6. Which of the following is not a valid PHP array type? a) Indexed


array b) Associative array c) Multidimensional array d) Double array

Answer: d) Double array


7. What does the explode() function do in PHP? a) Breaks a string
into an array b) Combines two arrays c) Removes white spaces from a
string d) All of the above

Answer: a) Breaks a string into an array

It's also mentioned that there were basic formality related questions
like "how you will work." This could refer to situational or behavioral
questions. Examples:

1. How would you approach a situation where you're unfamiliar


with a certain PHP function or library needed for a project?
Answer: I would start by reading the official PHP documentation or
the documentation related to the library. If I still have doubts, I might
ask a senior developer or turn to online forums like Stack Overflow.
Continuous learning is a part of development, and I believe in utilizing
all available resources to understand and implement solutions
effectively.
2. If you are stuck with a piece of code that isn't working as
expected, what steps would you take to troubleshoot the
problem?
Answer: I would begin by examining error messages or logs, if any.
Next, I'd break down the code to isolate the problematic section,
possibly using echo or print statements for debugging. If the issue
remains unresolved, I'd search for similar problems online or consult
with colleagues. Utilizing version control tools, like git, can also help to
identify when and where a problem was introduced.

8. What is the output of the following PHP code?

phpCopy code
$x = true && false ; var_dump ( $x );

a) bool(true) b) bool(false) c) NULL d) 0


Answer: b) bool(false)

9. Which function can be used to redirect the browser to a


different page? a) header() b) redirect() c) goto() d) move()

Answer: a) header()

10. Which superglobal does not get its values from the browser?
a) $_GET b) $_POST c) $_SESSION d) $_COOKIE

Answer: c) $_SESSION

11. How can you start a PHP session? a) start_session(); b)


begin_session(); c) session_start(); d) new_session();

Answer: c) session_start();

12. What is the correct way to end a PHP statement? a) . b) ; c) : d) !

Answer: b) ;

13. Which PHP function returns the current timestamp? a)


current_time() b) get_time() c) date() d) time()

Answer: d) time()

14. How do you retrieve data from a MySQL database in PHP? a)


use the RETRIEVE statement b) use the GET statement c) use the
SELECT statement with PDO or mysqli d) use the FETCH statement

Answer: c) use the SELECT statement with PDO or mysqli

15. Which function is used to escape special characters in a string


for use in an SQL statement? a) mysql_real_escape_string() b)
escape_string() c) addslashes() d) str_escape()
Answer: a) mysql_real_escape_string() (though it's worth noting that
this function is deprecated, and using parameterized queries with PDO
or mysqli is the modern and safer approach).

16. Which of the following functions will output the contents of a


PHP variable in a format suitable for debugging? a) print() b)
echo() c) var_dump() d) display()

Answer: c) var_dump()

17. What does the implode() function do in PHP? a) Breaks a string


into an array b) Converts an array into a string c) Reverses an array d)
Sorts an array

Answer: b) Converts an array into a string

18. What does $_SERVER['REMOTE_ADDR'] return? a) Server IP b)


User's IP Address c) Server software d) User's browser type

Answer: b) User's IP Address

19. Which of the following is NOT a valid PHP comparison


operator? a) === b) <=> c) == d) =<

Answer: d) =<

20. Which function returns a string's ASCII value? a) str_ascii() b)


to_ascii() c) ord() d) char()

Answer: c) ord()

21. What does PDO stand for in PHP? a) PHP Data Output b) PHP
Database Object c) PHP Data Object d) PHP Document Object

Answer: c) PHP Data Object


22. Which function can be used to check if a PHP extension is
loaded? a) is_extension() b) extension_loaded() c) load_extension() d)
check_extension()

Answer: b) extension_loaded()

23. What is the use of the die() function? a) Kill a process b)


Output a message and terminate the current script c) Delay execution
d) Debug a variable's value

Answer: b) Output a message and terminate the current script

24. Which function removes whitespace or other characters from


the beginning of a string? a) rtrim() b) ltrim() c) trim_start() d)
trim_left()

Answer: b) ltrim()

25. Which function is used to get the content of a file into a


string? a) file_to_string() b) get_file_contents() c) readfile() d)
file_get_contents()

Answer: d) file_get_contents()

26. How do you define a constant in PHP? a) const NAME = 'value';


b) define(NAME, 'value'); c) both a & b d) final NAME = 'value';

Answer: c) both a & b

27. Which PHP array function is used to take one or more arrays
and combine them? a) array_merge() b) array_combine() c)
array_concat() d) array_join()

Answer: a) array_merge()
28. How can you retrieve the value of a cookie in PHP? a)
$_COOKIE b) $_SESSION c) get_cookie() d) retrieve_cookie()

Answer: a) $_COOKIE

29. What is the default session name in PHP? a) PHP_SESSION b)


PHPSESSID c) SESSION_ID d) PHPID

Answer: b) PHPSESSID

30. What does NaN mean in PHP? a) Not a Name b) Not a Number c)
Not any Null d) No Argument Name

Answer: b) Not a Number

31. Which function changes all keys in an array to lowercase? a)


array_keys_lower() b) array_change_key_case() c) strtolower_array() d)
keys_tolower()

Answer: b) array_change_key_case()

32. Which PHP function is used to insert a new element in an


array? a) array_push() b) array_insert() c) array_add() d) array_place()

Answer: a) array_push()

33. Which function sorts an array in descending order? a) sort() b)


ksort() c) asort() d) rsort()

Answer: d) rsort()

34. Which function can be used to get the last error message in
PHP? a) error_get_last() b) get_error() c) error_message() d) last_error()

Answer: a) error_get_last()
35. Which of the following is not a magic constant in PHP? a) LINE
b) FILE c) DATE d) DIR

Answer: c) DATE

36. What is the correct way to add a comment in PHP that spans
multiple lines? a) // this is a comment b) <!-- this is a comment --> c)
/* this is a comment */ d) -- this is a comment --

Answer: c) /* this is a comment */

37. Which function returns the current script's path? a)


script_path() b) FILE c) path() d) get_path()

Answer: b) FILE

38. Which PHP function can we use to count the number of


elements in an array? a) count_elements() b) sizeof() c) array_length()
d) array_size()

Answer: b) sizeof() (but note that count() is also a correct function to


achieve this)

39. Which PHP function is used to replace a string? a) str_replace()


b) replace_str() c) replace() d) string_replace()

Answer: a) str_replace()

40. How can you enable error reporting in PHP? a)


error_reporting(E_ALL) b) set_error(E_ALL) c) enable_errors(E_ALL) d)
report_errors(E_ALL)

Answer: a) error_reporting(E_ALL)
41. What does the split() function do in PHP? a) Divides a string
by a regular expression b) Splits an array into chunks c) Splits a string
into a character array d) None of the above

Answer: a) Divides a string by a regular expression (though it's worth


noting that the split() function is deprecated in PHP)

42. Which function is used to search for a specific text within a


string? a) strpos() b) strstr() c) in_str() d) search()

Answer: a) strpos()

43. How can you increase the execution time of a PHP script? a)
set_time_limit() b) max_execution_time() c) increase_time() d)
script_time()

Answer: a) set_time_limit()

44. What does the compact() function do in PHP? a) Creates an


array containing variables and their values b) Reduces the memory size
of an array c) Compresses an array d) None of the above

Answer: a) Creates an array containing variables and their values

45. Which PHP function can be used to generate a random


number? a) random() b) rand_num() c) generate_rand() d) rand()

Answer: d) rand()

47. How can you retrieve the total number of rows returned by a
MySQL query? a) mysql_count_rows() b) mysql_rows() c)
mysql_num_rows() d) count_rows()

Answer: c) mysql_num_rows()
48. Which function in PHP is used to include content from
another file? a) #include b) require c) fetch d) open

Answer: b) require

52. Which of the following functions removes the first element


from an array? a) array_shift() b) array_unshift() c) array_pop() d)
array_push()

Answer: a) array_shift()

53. In a switch statement, what is used to prevent the code from


executing further cases after a match is found? a) stop b) end c)
break d) exit

Answer: c) break

54. How do you access a session variable in PHP named


"username"? a) $username b) $_SESSION[‘username’] c) $SESSION-
>username d) get_session(‘username’)

Answer: b) $_SESSION[‘username’]

55. Which of the following is NOT a valid filter in PHP filter


functions? a) FILTER_VALIDATE_EMAIL b) FILTER_SANITIZE_STRING c)
FILTER_CLEAN_URL d) FILTER_VALIDATE_INT

Answer: c) FILTER_CLEAN_URL

56. Which PHP function returns the number of characters in a


string? a) strlen() b) str_count() c) str_num() d) count_str()

Answer: a) strlen()
57. How can you destroy a PHP session? a) session_destroy() b)
destroy_session() c) session_end() d) end_session()

Answer: a) session_destroy()

59. What is the use of the serialize() function in PHP? a) Convert


a simple object to a string b) Convert a string to an array c) Convert an
array to a string d) Convert a string to a simple object

Answer: a) Convert a simple object to a string

61. What will the following code output?

phpCopy code
$a = 10 ; $b = 20 ; echo $a <=> $b ;

a) 1 b) 0 c) -1 d) None of the above

Answer: c) -1

In PHP, the <=> operator is known as the "spaceship operator". It's a


three-way comparison operator and is used for comparing two
expressions. The spaceship operator returns:

 -1 if the left operand is less than the right operand


 0 if both operands are equal
 1 if the left operand is greater than the right operand

You might also like