2.What is the value of $x after the following code?
$x = 1;
$y = 2;
if ($x != $y)
$x = $x * $y;
else
$x = $x + $y;
a. 2
b. NULL
c. 3
d. 1
3.Which of the following is the correct use of the concatenation operator?
a. $x = $This & $That;
b. $x = $This && $That;
c. $x = $This + $That;
d. $x = $This . $That;
4.What is the value of $x after the following code?
$foo = 1;
$foo += 5;
$x = $Foo;
a. NULL
b. 1
c. 5
d. 6
5.Which of the following is NOT a valid way to increment $nothing?
a. ++$nothing;
b. $nothing = $n + $nothing;
c. $nothing = +$n;
d. $nothing++;
6.Which of the following is a valid variable name?
a. $1Var
b. 1Var
c. $My-Var
d. $MyVar
7.Which of the following answers is a valid database connection statement, based on the following code?
$hostname = 'localhost';
$user = 'root';
$password = 'sesame';
$database 'Employees';*
a. mysql_connect($database, $database, $user, $password);
b. mysql_connect($hostname, $user, $password, $database);
c. mysql_connect($hostname, $user, $password);
d. mysql_connect($hostname, $database);
8.Which of the following is a valid SELECT statement?*
a. $SQL = 'SELECT name, address FROM customers WHERE id = 1';
b. $SQL = 'FROM customers SELECT name, address WHERE id = 1';
c. $SQL = 'SELECT name, address, id = 1 FROM customers';
d. $SQL = 'SELECT name, address WHERE id = 1 FROM customers';
9.What is the output of the following expression:
$a = "b";
$b = "c";
$c = "a";
echo $$$$a;
a. Parse
b. c
c. a
d. b
10.What is the output of the following expression
$d = 10;
function myFunction($d) {
return ++$d;
}
myFunction($d++);
echo $d;*
a. NULL
b. 12
c. 10
d. 11
11.What is the output of the following expression:
$f = 7;
function myFunction(&$d) {
return $d++;
}myFunction($f);
echo $f;*
a. None of the above
b. 7
c. 78
d. 8
12.What is the output of the following expression:
$a = array(1, 2, 3, 4, 5);
echo array_shift($a);*
a. 5
b. null
c. 1
d. 1,2,3,4,5
13.What is the output of the following code:
class myClass {
public $z;
public function __construct($z = 5) {
$this->z = 10;
}
}
$a = new myClass();
$b = $a;
$b->z = 0;
echo $a->z;*
a. 5
b. 0
c. 15
d. 10
14.What is the value of the array $a:
$a = array_combine(array('A', 'B', 'C'), array(1, 2, 3));
a. array(1 => 'A', 2 => 'B', 3 => 'C')
b. array('A' => 1, 'B' => 2, 'C' => 3)
c. array(array('A', 'B', 'C'), array(1, 2, 3))
d. array('A', 'B', 'C', 1, 2, 3)
15.Which of the following expressions correctly checks the type AND value so that the expression evaluates to FALSE?
$a = '';
$b = 0;*
a. $a == false
b. $b === false
c. !$a
d. $b == false
16.What does the following string do?
$rest = substr ("abcdef", 1, 3);*
a. sets the variable $rest to "def"
b. sets the variable $rest to "cdf"
c. sets the variable $rest to "abc"
d. sets the variable $rest to "bcd"
17.What is the output of the following code:
class A {
protected $x = 10;
public function myMethod($x=0) {
return $this->x;
}
}
class B extends A {
public function myMethod($x=0) {
return 2 * $this->x;
}
}
$m = new B(5);
echo $m->myMethod();
a. 15
b. 5
c. 10
d. 20
18.What is the output of the following code:
$vehicles = array('car', 'truck', 'van', 'bus');
current($vehicles);
next($vehicles);
each($vehicles);
echo current($vehicles);*
a. car
b. truck
c. bus
d. van
19.What is the output of the following code:
switch (5 % 2) {
case 1:
echo 1;
case 2:
echo 2;
case 3:
echo 3;
break;
default:
echo 0;
}*
a. 12
b. 1
c. 0
d. 123
20.If you wanted to use the ASP escape characters(<% %>), what do you need to do?
a. Install PHP with ASP support checked
b. Edit the php.ini file and change USEASPCHARACTERS to TRUE.
c. Nothing, PHP uses them by default.
d. Edit the php.ini file and change asp_tags to On.
21.Which expression does not result in $a = 5?
a. $a = ($b = 5);
b. $a = 4; $a = $a++;
c. $a = 4; $a = ++$a;
d. $a = $b = 5;
Last modification:June 17, 2020
© Allow specification reprint
Comment here is closed