PHP Flashcards
Who is designed by PHP ?
Rasmus Lerdorf
PHP initial release date ?
1995
What does PHP stand for?
Hypertext Preprocessor
PHP files have a default file extension of
.php
What is/are PHP code editors ?
Adobe Dreamweaver
Notepad
Notepad++
Which of the following correct PHP syntax?
<?php…?>
What is WAMP server ?
Windows Apache MySQL PHP
In PHP, instructions are terminated by using what?
;
What is a correct way to add a comment in PHP?
/…/
How do you write “Hello World” in PHP
echo “Hello World”;
What type specifier is invalid in print f() functions ?
% a
PHP Variable start with which symbol?
$
The PHP syntax is most similar to:
Perl and C
What is the correct way to include the file “header.inc” ?
<?php include “header.inc”; ?>
In PHP what is the difference between include() and require() ?
They are different how they handle failure
To process image what library needed in PHP?
GD Library
In PHP, what function is used to insert content of one php file into another php file before server executes ?
include()
What function is used to redirect a page ?
header()
PHP variables are_____ ?
Multitype variables
How can we check the value of a given variable is a number?
is_numeric()
What variable assignment is ‘by value’ assignment in PHP ?
$value1= $value?
How can we check the value of a given variable is alphanumeric?
ctype_alnum()
How do I check if a given variable is empty?
empty()
Identify the variable scope that is not supported by PHP ?
Hidden variables
What is the correct way to create a function in PHP?
function myFunction()
What is the correct way to open the file “footer.txt” as readable?
fopen(“footer.txt”,”r”);
Which version of PHP introduced Try/catch Exception ?
PHP 5
What PHP function can be used to find files ?
glob()
The left association operator % is used in PHP for ?
bitwise or
In PHP what is the best all-purpose way of comparing two strings ?
Using strcmp()
What will be the value of $var?
$var = 1 / 2;
0.5
What function returns the number of characters in a string variable ?
strlen($variable)
How do you get information from a form when method is “post”?
$_POST[ ];
In php which method is used to get browser properties?
$_SERVER[‘HTTP_USER_AGENT’];
In PHP what gives a string containing PHP script file name in which it is called ?
$_PHP_SELF
Which superglobal variable holds information about headers, paths, and script locations?
$_SERVER
Which type of variables are floating-point numbers, like 3.14159 or 49.1 ?
Doubles
In PHP which method sends input to a script through(via) a URL ?
Get
What is the correct way to add 1 to the $count variable?
$count++;
Which one of these variables has an illegal name?
A) $my_Var
B) $my-Var <=this one
C) $myVar
D) $_myVar
B is the correct answer
Which are compound data type?
Array
and
Objects
Which method acts as a constructor function in a PHP class ?
__construct
How do you create an array in PHP?
$cars = array(“Volvo”, “BMW”, “Toyota”);
How do we access the value of ‘d’ later?
$a = array(
‘a’,
3 => ‘b’,
1 => ‘c’,
‘d’
);
$a[4]
What will be printed?
<?php
$a = array(
null => ‘a’,
true => ‘b’,
false => ‘c’,
0 => ‘d’,
1 => ‘e’,
‘’ => ‘f’
);
echo count($a), “\n”;
?>
3
What will be the output of the following PHP code?
<?php
define(“Hi”,”Hello! How are you ?”);
echo constant(“Hi”);
?>
Hello! How are you ?
Which in-built function will add a value to the end of an array ?
array_push()
Which two predefined variables are used to retrieve information from forms ?
$_GET & $_SET
How to start session in php?
session_start()
What is used to check that a cookie is set or not ?
isset() function
How do you create a cookie in PHP?
setcookie()
In PHP what is not a session function ?
A) session_destroy
B) session_decode
C) session_id
D) session_pw
Correct Answer : Option (D) :
session_pw
In PHP the function setcookie( ) is used to ?
Store data in cookie variable
What is the purpose of $_SESSION[]?
Used to store variables of the current session
What is the default execution time set in set_time_limit()?
30 secs
Which statement about the code below is correct?
<?php
class A {}
class B {}
class C extends A, B {}
?>
class C can not extend both A and B
Which of the following is true about php.ini file ?
A)
The php.ini file is read each time PHP is initialized.
B)
The PHP configuration file, php.ini, is the final and most immediate way to affect the functionality of PHP.
C)
All of the above
D)
None of the above
Correct Answer : Option (C) :
All of the above
Which function returns an array consisting of associative key/value pairs ?
array_count_values()
Which operator is used to check if two values are equal and of same data type?
===
What is the use of explode() in PHP?
Used to split a string by a string
How do I create PHP arrays in a HTML <form>?
<input></input>
In which variable is the users IP address stored?
$REMOTE_ADDR
Which of the following method can be used to create a MySql database using PHP ?
mysql_query()
Which functions is used to get the height of an image :
imagesy()
What is the function file_get_contents() useful for?
read
Which of the following is NOT a valid PHP comparison operator?
&&&
How to determine number of rows returned in result set?
mysqli_num_rows()
Which one of the following function is used to send a e-mail using PHP script ?
mail()
Which function gives us the number of affected entries by a query?
mysqli_affected_rows()
What is the default upload file size in php?
2 MB
Which method can be used to close a MySQL database using PHP ?
mysql_close()
In PHP the error control operator is _______ ?
@
What is the output ?
<?php
define(“x”,”5”);
$x=x+10;
echo x;
?>
5
there’s an issue with the code. The constant “x” is defined with double quotes around its name and value, which is not the correct syntax for defining constants in PHP. It should use single quotes or no quotes at all for both the constant name and value. Here’s the corrected code:
define(“x”, 5);
$x = x + 10;
echo $x;
What is the output.
<?php
$x=array(1,3,2,3,7,8,9,7,3);
$y=array_count_values($x);
echo $y[9];
?>
1
What will be printed ?
if (null === false) {
echo ‘true’;
} else {
echo ‘false’;
}
false
The triple equal sign comparison operator not only checks if the variables are equal in value, but it also confirms that they are of the same type before it returns true or false .
What is the difference between echo and print?
Echo can take multiple parameters where as print cannot
What is the perfect output ?
<?php
$RESULT = 11 + 011 + 0x11;
echo “$RESULT”;
?>
37
$RESULT is a variable where the result of a calculation will be stored. 11 is a decimal number (base 10) and is equal to 11. 011 is an octal number (base 8) because it starts with a leading zero. In octal, 011 is equal to 9 in decimal. 0x11 is a hexadecimal number (base 16) because it starts with "0x." In hexadecimal, 0x11 is equal to 17 in decimal.
Now, let’s calculate the result:
11 (decimal) + 9 (octal) + 17 (hexadecimal) = 37 (decimal)
So, the variable $RESULT holds the value 37.
What is the correct abstract method?
abstract public function write();
What array represents an array with a numeric index?
Numeric Array
In mail($param2, $param2, $param3, $param4), the $param2 contains:
The subject
Which of following function return 1 when output is successful?
print ( )
Which function is used to strip whitespace (or other characters) from the beginning and end of a string?
trim
Which of the following is not true?
PHP applications can not be compiled
If a boolean variable $ alive= 5;
$ alive is true
Which PHP functions accepts any number of parameters?
func_get_args()
Which of following is not a Superglobals in PHP?
$_PUT
What will be the output of the following PHP code?
<?php $a = 5; $b = 5; echo ($a === $b); ?>
1
It assigns the value 5 to a variable named "$a." It assigns the value 5 to another variable named "$b." It then checks if the value of "$a" is exactly the same as the value of "$b" using "===". Finally, it prints (echos) the result of this comparison.
Which of the conditional statements is/are supported by PHP?
i) if statements
ii) if-else statements
iii) if-elseif statements
iv) switch statements
i), ii), iii) and iv)
Which of the looping statements is/are supported by PHP?
i) for loop
ii) while loop
iii) do-while loop
iv) foreach loop
A) i) and ii)
B) i), ii) and iii)
C) i), ii), iii) and iv)
D) None of the above
Correct Answer : Option (C) : i), ii), iii) and iv)
What will be the value of $a and $b after the function call in the following PHP code?
<?php function doSomething( &$arg ) { $return = $arg; $arg += 1; return $return; } $a = 3; $b = doSomething( $a ); ?>
a is 4 and b is 3
The value of $a becomes 4 because it was modified within the doSomething function. The value of $b becomes 3 because it received the original value of $a before the modification due to the return $return; statement.
So, at the end of this code, $a holds 4, and $b holds 3.
If $a = 12 what will be returned when ($a == 12) ?
5
Type Hinting was introduced in which version of PHP?
PHP 5
What will be the output of the following PHP code?
<?php
function a()
{
function b()
{
echo ‘I am b’;
}
echo ‘I am a’;
}
a();
a();
?>
I am a
when run thru a complier: ERROR!
Parse error: syntax error, unexpected identifier “am”, expecting “,” or “;” in /tmp/1HPOaj7nVx.php on line 8
A function in PHP which starts with __ (double underscore) is known as ___
Magic Function
PHP’s numerically indexed array begin with position ___________
0
Which of the following are correct ways of creating an array?
i) state[0] = “nellore”;
ii) $state[] = array(“nellore”);
iii) $state[0] = “nellore”;
iv) $state = array(“nellore”);
iii) and iv)
Which PHP function will return true if a variable is an array or false if it is not an array?
is_array()