Skip to content

PHP MCQ Questions

0
Answered
0
Correct
0%
Accuracy
Q101 Easy

What is the purpose of adding a lowercase "u" as a modifier after the final delimiter in a Perl-compatible regular expression?

Q102 Easy

What is the output of the following code: "<?php $x = 0x22; echo <<<'END' $x END; ?>"

Q103 Easy

What is the correct PHP command for setting a MySQL connection character set to UTF8?

Q104 Easy

What is the difference between $a == $b and $a === $b in PHP?

Q105 Easy

What is the result of the following: $a = (2 == '2') ? true : false; echo $a;

Q106 Easy

What is the output of the following code? class Foo { private $foo; protected $bar; public $test; public function __construct() { $this->foo = 1; $this->bar = 2; $this->test = 3; } } print_r( (array) new Foo );

Q107 Easy

What is the value of "n1" and "n2" after executing the following code? var str = "Finding foo in Foo and Bar"; var n1 = str.search("Foo"); var n2 = str.search(/Foo/i);

Q108 Easy

What is the output of the following code? class angryBob{ public function angryBob(){ $this->apple = "Taken away by Bob"; } } class sillyBill extends angryBob{ var $apple; public function sillyBill() { $this->apple = "Eaten by Bill"; parent::angryBob(); } } $Bill = new sillyBill; echo $Bill->apple;

Q109 Easy

What is the output of the following code? try { $a = 10/0; echo $a; } catch (Exception $e) { echo 'You cannot divide by ZERO!!'; }

Q110 Easy

What is the difference between the float and the double type in PHP?

Q111 Easy

What is default session time in PHP?

Q112 Easy

What is the output of the following code? $a = '12345'; $a[$a[2]] = 3; echo $a;

Q113 Easy

What is the correct use of the constant, PHP_EOL?

Q114 Easy

What is the output of the following code? session_start(); $_SESSION['logged_in'] = true; $_SESSION['name'] = 'Jane'; $_SESSION['level'] = 4; echo session_encode();

Q115 Easy

What is a type of PHP error severity? (choose all that apply)

Q116 Easy

What is the best method for sanitizing user input with PHP?

Q117 Easy

Given this code: function doSomething( &$arg ) { $return = $arg; $arg += 1; return $return; } $a = 3; $b = doSomething( $a ); what is the value of $a and $b after the function call?

Q118 Easy

What is the output of the following code?echo '1'.print(2) + 3;

Q119 Easy

What is the output of the following code run using PHP 5.6.0 or higher? const ONE = 1; class foo { const TWO = ONE * 2; const THREE = ONE + self::TWO; const SENTENCE = 'The value of THREE is '.self::THREE; } echo foo::SENTENCE . "\n";

Q120 Easy

What will be the output of the following code? <?php $xmlFile = "<root><css><element><csstag><title>background-color</title><value>#FFF</value></csstag><csstag><title>color</title><value>#333</value></csstag><csstag><title>font-family</title><value>Verdana, Geneva, sans-serif</value></csstag></element></css></root>"; $xml = simplexml_load_string($xmlFile); foreach($xml->css as $css) { echo (string) $css->element['id']."{"; foreach($xml->css->element->csstag as $tag) { $temp = $tag->title.": ".$tag->value.";"; echo $temp; } echo "}"; } ?>

Q121 Easy

What is the output from this example? $str = "My name is O\'Connor."; echo stripslashes($str);

Q122 Easy

What is the recommendation regarding PHP closing tags in a document?

Q123 Easy

In PHP5, what is the difference between using self and $this, and when is each appropriate?

Q124 Easy

What is meaning of PEAR?

Q125 Easy

What is the difference between $name and $$name

Q126 Easy

What is the output of the following code? function luckyA (&$beebar){ $beebar *= 2; return $beebar; } $x= 4; $y = luckyA($x); $x += 5; echo $x . ', ' . $y;

Q127 Easy

What is the name of the PHP configuration file?

Q128 Easy

What is the output of the following code? $foo = 10; $bar = '10'; if ($foo === $bar){ echo 'I ran'; }

Q129 Easy

What is the opening tag for PHP

Q130 Easy

what is array_column?

Q131 Easy

What is the result of the following code? $integer = 5; $string = strval($integer); var_dump($string);

Q132 Easy

What is the difference between die() and exit() in PHP?

Q133 Easy

What is the output of the following code? $foo = 400; $bar = 10; echo $foo . "+" . $bar;

Q134 Easy

What is the output when the following code is executed? <?php function myFun($a) { if (!$a) { throw new Exception('Value init.'); } return 3/$a; } try { echo myFun(3) . "\n"; } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } finally { echo "first\n"; } try { echo myFun(1) . "\n"; } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } finally { echo "second\n"; } echo "Hello PHP Example\n"; ?>

Q135 Easy

What is the output of the following code? $a='20'; $a -= 5; echo $a++;

Q136 Easy

In the PHP code given below, what is/are the properties?

Q137 Easy

What is the output of the following code? $a = "b"; $b = 22; echo $$a + 40;

Q138 Easy

What is a class in PHP?