现在的位置: 首页 > 综合 > 正文

PHP 基础测试题(6~10)

2013年08月07日 ⁄ 综合 ⁄ 共 1581字 ⁄ 字号 评论关闭
网眼 2009-03-19 22:09:46 回复 置顶 修改 删除
6. What is the output of the following script?
$a = 10;
$b = 20;
$c = 4;
$d = 8;
$e = 1.0;
$f = $c + $d * 2;
$g = $f % 20;
$h = $b - $a + $c + 2;
$i = $h << $c;
$j = $i * $e;
print $j;
?>
A.128
B.42
C.242.0
D.256
E.342
 
7. Which values should be assigned to the variables $a, $b and $c in order for the following
script to display the string Hello, World!?
$string = "Hello, World!";
$a = ?;
$b = ?;
$c = ?;
if($a) {
if($b && !$c) {
echo "Goodbye Cruel World!";
} else if(!$b && !$c) {
echo "Nothing here";
}
} else {
if(!$b){
if(!$a && (!$b && $c)) {
echo "Hello, World!";
} else {
echo "Goodbye World!";
}
} else {
echo "Not quite.";
}
}
?>
A.False, True, False
B.True, True, False
C.False, True, True
D.False, False, True
E.True, True, True
 
8. What will the following script output?
$array = '0123456789ABCDEFG';
$s = '';
for ($i = 1; $i < 50; $i++) {
$s .= $array[rand(0,strlen ($array) - 1)];
}
echo $s;
?>
16
PHP Programming Basics
A.A string of 50 random characters
B.A string of 49 copies of the same character, because the random number generator has not been initialized
C.A string of 49 random characters
D.Nothing, because $array is not an array
E.A string of 49 ‘G’ characters
 
9. Which language construct can best represent the following series of if conditionals?
if($a == 'a') {
somefunction();
} else if ($a == 'b') {
anotherfunction();
} else if ($a == 'c') {
dosomething();
} else {
donothing();
}
?>
A.A switch statement without a default case
B.A recursive function call
C.A while statement
D.It is the only representation of this logic
E.A switch statement using a default case
 
10. What is the best way to iterate through the $myarray array, assuming you want to modify the
value of each element as you do?
$myarray = array ("My String",
"Another String",
"Hi, Mom!");
?>
A.Using a for loop
B.Using a foreach loop
C.Using a while loop
D.Using a do…while loop
E.There is no way to accomplish this goal

抱歉!评论已关闭.