menu

PHP Basics


1. Which of the following is used to generate a random number in PHP?

rand()

random()

random_number()

generate_random_number()


2. What is the correct way to assign a value to a variable in PHP?

x = 5;

$x = "5";

$x == 5;

$x = 5;


3. Which of the following is used to check if a variable is a resource in PHP?

is_resource()

resource()

isResource()

none of the above


4. Which of the following is not a valid variable name in PHP?

$my_var

$MyVar

$_myvar

$my-var


5. Which of the following is used to redirect a user to a different page in PHP?

header()

redirect()

location()

navigate()


6. Which of the following is used to add an element to the beginning of an array in PHP?

array_push()

array_pop()

array_shift()

array_unshift()


7. Which of the following is used to check if a variable is set and not NULL in PHP?

isset()

empty()

defined()

none of the above


8. Which of the following is used to set a cookie in PHP?

setcookie()

createcookie()

set_cookie()

create_cookie()


9. Which of the following is used to display the contents of an array in PHP?

echo()

print()

var_dump()

all of the above


10. Which of the following is used to test if two values are identical in PHP?

==

=

===

!=