PHP Basic

Q 1.What does PHP stand for?

A. Personal Home Page

B. Hypertext Preprocessor

C. Pretext Hypertext Processor

D. Preprocessor Home Page

A. Both A and C

B. Both B and D

C. Only B

D. Both A and B

Show Answer Answer:- D.Both 1 and 2
Explanation PHP previously stood for Personal Home Page now stands for Hypertext Preprocessor.

Q 2.PHP files have a default file extension of_______.

A ..html

B ..xml

C ..php

D ..ph

Show Answer Answer:-C ..php

Q 3.Which of the following is/are a PHP code editor?

A . Notepad

B . Notepad++

C . Adobe Dreamweaver

D . PDT

A .Only D

B .All of the mentioned

C .A, B and C

D .Only C

Show Answer Answer:-B.All of the mentioned
Explanation Any of the above editors can be used to type php code and run it.

Q 4.Which of the following must be installed on your computer so as to run PHP script?

A. Adobe Dreamweaver

B. PHP

C 3. Apache

D . IIS

A . Only B

B . B and C

C .B, C and D

D .All of the mentioned.

Show Answer Answer:-C .B, C and D
Explanation To run PHP code you need to have PHP and a web server, both IIS and Apache are web servers.You can choose either one according to your platform.

Q 5.Which version of PHP introduced Try/catch Exception?

A .PHP 4

B .PHP 5

C .PHP 5.3

D .PHP 6

Show Answer Answer:-B.PHP 5
Explanation Version 5 added support for Exception Handling.

Q 6.We can use _________ to comment a single line?

A . /?

B . //

C . #

D . /* */

A. Only B

B. A, C and D

C. B, C and D

D. Both B and D

Show Answer Answer:-C. B, C and D
Explanation /* */ can also be use to comment just a single line although it is used for paragraphs. // and # are used only for single line comment.

Q 7. Which of the following php statement/statements will store 111 in variable num?

A . int $num = 111;

B . int mum = 111;

C . $num = 111;

D . 111 = $num;

A. Both A and B

B. Only A

C. Only C

D. All of the mentioned

Show Answer Answer:-C. Only C
Explanation You need not specify the datatype in php.

Q 8.What will be the output of the following php code?

<?php

$num = 1;

$num1 = 2;

print $num . “+”. $num1;

?>

A. 3

B. 1+2

C. 1.+.2

D. Error

Show Answer Answer:-B. 1+2
Explanation (dot) is used to combine two parts of the statement. Example ( $num . “Hello World” ) will output 1Hello World.

Q 9.What will be the output of the following php code?

<?php

$num = “1”;

$num1 = “2”;

print $num+$num1;

?>

A. 3

B. 1+2

C. Error

D. 12

Show Answer Answer:-A.3
Explanation The numbers inside the double quotes are considered as integers and not string, therefore the value 3 is printed and not 1+2.

Q 10.Which of following variables can be assigned a value to it?

A 1. $3hello

B 2. $_hello

C 3. $this

D 4. $This

A. Only B

B. B, C and D

C. B and D

D. All of the mentioned

Show Answer Answer:-C. B and D
Explanation A variable can’t start with a number. Also $this is a special variable that can’t be assigned, but $This can be assigned.

Q 11.What will be the output of the following code?

<?php

$foo = ‘Bob’;

$bar = &$foo;

$bar = “My name is $bar”;

echo $bar;

echo $foo; ?>

A. Error

B. My name is BobBob

C. My name is BobMy name is Bob

D. My name is Bob Bob

Show Answer Answer:-C.My name is BobMy name is Bob
Explanation The $bar = &$foo; line will reference $foo via $bar.

Q 12.Which of the following PHP statements will output Hello World on the screen?

A . echo (“Hello World”);

B . print (“Hello World”);

C . printf (“Hello World”);

D . sprintf (“Hello World”);

A. A and B

B. A, B and C

C. A, B and D

D. All of the mentioned

Show Answer Answer:-B. A, B and C
Explanation echo(), print() and printf() all three can be used to output a statement onto the screen. The sprintf() statement is functionally identical to printf() except that the output is assigned to a string rather than rendered to the browser.

Q 13.What will be the output of the following PHP code?

<?php

$color = “maroon”;

$var = $color[2];

echo “$var”;

?>

A. a

B. Error

C. $var

D. r

Show Answer Answer:-D. r
Explanation PHP treats strings in the same fashion as arrays, allowing for specific characters to be accessed via array offset notation.

Q 14.What will be the output of the following PHP code?

<?php

$score = 1234;

$scoreboard = (array) $score;

echo $scoreboard[0];

?>

A. 1

B. Error

C. 1234

D. 2

Show Answer Answer:-C.1234
Explanation The (array) is a cast operator which is used for converting values from other data types to array.

Q 15.What will be the output of the following PHP code?

<?php

$total = “25 students”;

$more = 10;

$total = $total + $more;

echo “$total”;

?>

A.Error

B.35 students

C.35

D.25 students

Show Answer Answer:-C.35
Explanation The integer value at the beginning of the original $total string is used in the calculation. However if it begins with anything but a numerical value, the value will be 0.

Q 16.Which of the below statements is equivalent to $add += $add ?

A. $add = $add

B. $add = $add +$add

C. $add = $add + 1

D. $add = $add + $add + 1

Show Answer Answer:-B.$add = $add +$add
Explanation a += b is an addition assignment whose outcome is a = a + b. Same can be done with subtraction ,multiplication ,division etc.

Q 17.Which statement will output $p on the screen?

A. echo “\$p”;

B. echo “$$p”;

C. echo “/$xp”;

D. echo “$p;”;

Show Answer Answer:-A.echo “\$p”;
Explanation A backslash is used so that the dollar sign is treated as a normal string character rather than prompt PHP to treat $x as a variable. The backslash used in this manner is known as escape character.

Q 18.What will be the output of the following code?

<?php

function track()

{

static $count = 0;

$count++;

echo $count;

}

track();

track();

track();

?>

A. 123

B. 111

C. 000

D. 011

Show Answer Answer:-A. 123
Explanation Because $count is static, it retains its previous value each time the function is executed.

Q 19.What will be the output of the following PHP code?

<?php

$a = “clue”;

$a .= “get”;

echo “$a”; ?>

A. get

B. true

C. false

D. clueget

Show Answer Answer:-D. clueget
Explanation .= is a concatenation-assignment. $a equals its current value concatenated with “get”.

Q 20.What will be the output of the following PHP code?

<?

php $a = 5;

$b = 5;

span class=”sys-fun”>echo ($a === $b);

?>

A. 5 === 5

B. Error

C. 1

D. False

Show Answer Answer:-C.1
Explanation === operator returns 1 if $a and $b are equivalent and $a and $b have the same type.

Q 21.Which of the below symbols is a newline character?

A. \r

B. \n

C. /n

D. /r

Show Answer Answer:-B.\n
Explanation PHP treats \n as newline character.

Q 22.What will be the output of the following PHP code?

<?php

$num = 10;

echo ‘What is her age? \n She is $num years old’;

?>

A. What is her age? n She is $num years old

B. What is her age? She is $num years old

C. What is her age? She is 10 years old

D. What is her age?n She is 10 years old

Show Answer Answer:-A. What is her age? n She is $num years old
Explanation When a string is enclosed within single quotes both variables and escape sequences will not be interpreted when the string is parsed.

Q 23.Which of the conditional statements is/are supported by PHP?

A . if statements

B . if-else statements

C . if-elseif statements

D . switch statements

A. Only A

B. A, B and D

C. B, C and D

D. All of the mentioned.

Show Answer Answer:-D. All of the mentioned.

Q 24.What will be the output of the following PHP code?

<?php

$team = “arsenal”;

switch ($team)

{

case “manu”:

echo “I love man u”;

case “arsenal”:

echo “I love arsenal”;

case “manc”:

echo “I love manc”;

}

?>

A. I love arsenal

B. Error

C. I love arsenalI love manc

D. I love arsenalI love mancI love manu

Show Answer Answer:-C.I love arsenalI love manc
Explanation If a break statement isn’t present, all subsequent case blocks will execute until a break statement is located.

Q 25.Which of the looping statements is/are supported by PHP?

A . for loop

B . while loop

C . do-while loop

D . foreach loop

A. A and B

B. A, B and C

C. All of the mentioned

D. None of the mentione

Show Answer Answer:-C.All of the mentioned

Q 26.What will be the output of the following PHP code?

<?php

$user = array(“Ashley”, “Bale”, “Shrek”, “Blank”);

for ($x=0; $x < count($user); $x++)

{

if ($user[$x] == “Shrek”) continue;

printf ($user[$x]);

}

?>

A. AshleyBale

B. AshleyBaleBlank

C. ShrekBlank

D. Shrek

Show Answer Answer:-B. AshleyBaleBlank
Explanation The continue statement causes execution of the current loop iteration to end and commence at the beginning of the next iteration.

Q 27.If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?

A. 12

B. 1

C. Error

D. 5

Show Answer Answer:-D.5
Explanation ?: is known as ternary operator. If condition is true then the part just after the ? is executed else the part after : .

Q 28.What is the value of $a and $b after the function call?

<?php

function doSomething( &$arg )

{

$return = $arg;

$arg += 1;

return $return;

}

$a = 3;

$b = doSomething( $a );

?>

A. a is 3 and b is 4

B. a is 4 and b is 3

C. Both are 3

D. Both are 4

Show Answer Answer:-B. a is 4 and b is 3
Explanation $a is 4 and $b is 3. The former because $arg is passed by reference, the latter because the return value of the function is a copy of the initial value of the argument.

Q 29.Who is the father of PHP?

A. Rasmus Lerdorf

B. Willam Makepiece

C. Drek Kolkevi

D. List

Show Answer Answer:-A. Rasmus Lerdorf

Q 30.How does the identity operator === compare two values?

A.It converts them to a common compatible data type and then compares the resulting values

B.It returns True only if they are both of the same type and value

C.If the two values are strings, it performs a lexical comparison

D.It bases its comparison on the C strcmp function exclusively

E.It converts both values to strings and compares them

Show Answer Answer:-A.It converts them to a common compatible data type and then compares the resulting values

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page