Professional Documents
Culture Documents
22. Which of the following tags is not a valid way to begin and end a PHP code block?
a. <% %>
b. <?php ?>
c. <? ?>
d. <?= ?>
e. <!-- -->
<?php
define(pet, "4");
$mypet[4] = "Chicken";
$mypet[] = "Human";
$mypet ['pet'] = "Sheep";
$mypet ["Sheep"] = "Cat";
print "The value is: ";
print $ mypet[pet]."\n";
?>
<?php
$a = 10;
$b = 5;
$c = 4;
$d = 8;
$e = 1.0;
$b++;
$c=(--$a)+$b++;
$f = $c + $d * 2;
$g = $f % 10;
print $g;
?>
a. -1
b. 0
c. 1
d. 2
e. 3
25. Consider the following segment of code:
<?php
define("LIMIT", 2187);
$result= array();
echo "<pre>";
print_r($result);
echo "</pre>";
?>
What should go in the marked segment to produce the following array output?
Array
(
[0] => 1
[1] => 3
[2] => 9
[3] => 27
[4] => 81
[5] => 243
[6] => 729
)
26. What is the value displayed when the following is executed? Assume that the code was
executed using the following URL: obiesan.php?c=14
<?php
global $e;
$retval = $c + $d - $_GET['c'] - $e;
return $retval;
}
$e = 5;
echo process(7);
?>
a. -12
b. -1
c. 0
d. 1
e. 12
27. Which of the following is not valid PHP code?
a. $_999;
b. $10satu
c. ${“TestAja”}
d. &$testsatu
e. $ApasaRTF
28. How can the index.php script access the NIM or email form element of the following HTML form?
(Choose 2)
a. $_GET['email']
b. $_POST['email']
c. $_SESSION['NIM’]
d. $_REQUEST['NIM']
e. $_POST['text']
29. Consider the following form and subsequent script. What will the script print out if the user
types the word “poltek” and “student” in the two text boxes respectively?
<?php
echo $_GET[‘variable’];
?>
a. Nothing
b. Array
c. A notice
d. phpgreat
e. greatphp
30. Consider the following array, called $multi_array. How would the value cat be referenced
within the $multi_array array?
<?php
$nested_array = array("white",
"green",
"black" => 67,
30 => "red",
"yellow" => array("durian",
50 => "banana",
"cat" => 40,
"purple" => array("dog","cat","iguana")
)
);
?>
a. $multi_array['yellow']['cat']
b. $multi_array[5][2]
c. $multi_array[4][3][1]
d. $multi_array['yellow']['purple']['cat']
e. $multi_array['yellow']['purple'][1]