Learn PHP MCQs

Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.

How do you find the current line number in a PHP script?

1) __LINE__

2) __FILE__

3) __CURRENT__

4) __NUM__

Answer : Option 1

Which function is used to return the number of characters in a string?

1) strlen()

2) strcount()

3) strlength()

4) charcount()

Answer : Option 1

Which function is used to get the value of a constant in PHP?

1) constant()

2) getconst()

3) const()

4) getconstant()

Answer : Option 1

Which function is used to generate a random number in PHP?

1) rand()

2) random()

3) getrand()

4) generate_random()

Answer : Option 1

How do you convert a string to an integer in PHP?

1) intval()

2) strtoint()

3) stringtoint()

4) str_to_int()

Answer : Option 1

Which function is used to calculate the sum of values in an array?

1) array_sum()

2) sum()

3) arr_sum()

4) calc_sum()

Answer : Option 1

Which function is used to remove duplicate values from an array in PHP?

1) array_unique()

2) unique()

3) arr_unique()

4) remove_duplicates()

Answer : Option 1

Which function is used to shuffle the elements of an array in PHP?

1) shuffle()

2) randomize()

3) arr_shuffle()

4) array_randomize()

Answer : Option 1

How do you convert a string to uppercase in PHP?

1) strtoupper()

2) toupper()

3) stringtoUpper()

4) str_upper()

Answer : Option 1

Which of the following is a valid way to create a comment in PHP?

1) // Comment

2) /* Comment */

3) # Comment

4) All of the above

Answer : Option 4