php 基础测试题

选择题
1.下面哪个函数可以检测变量是否设置(C)
A. is_Array
B. unset
C. isset
D. empty

{is_Array:检测数组。
empty:检测变量是否为空或零,当为空或为零的时候返回true。}

2.语句for( $ k=0; $ k=1; $ k++ );和语句for($ k=0;$ k==1;$ k++);执行的次数分别是(B)
A.0和无限
B. 无限和0
C. 都是0
D. 都是无限
3. 在数组的末尾添加数组元素的函数是(D)
A. array_pop
B. array_shift
C. array_unshift
D. array_push

{array_pop:删除数组的最后一个元素。
array_shift:删除数组中的第一个元素。
array_unshift:向数组的开头位置添加一个或多个元素。
array_push:向数组最后添加一个或多个元素。}

下列哪些符号是PHP中的单行注释(BC)(多选)
A. / * … * /
B. #
C. //
D. <!…>
5.以下哪列选项是获取PHP版本的常量(C)
A. __ FILE __
B. __ LINE __
C. PHP_VERSION
D.PHP_OS
{__ FILE__:输出当前文件路径
__ LINE __:当前语句所在的行数
PHP_VERSION:当前PHP版本
PHP_OS:当前系统}

6.阅读下列代码,运行结果是(D)
$ i=0;
while($ i<10){
if($ i<1){
continue;
}
if($ i == 5){
break;
}
$ i++;
}
A. 1
B. 10
C. 6
D. 死循环
7. 下列哪些是合法的变量名(AC)(多选)
A.$ name
B. name
C.$_name
D. $ 9name
8.阅读下面程序片段,输出结果是(C)
$ a=0;
while ($ a<5){
switch($ a){
case 0:
case 3:$ a=$ a+2;
case 1:
case 2:$ a=$ a+3;
default:$ a=$ a+5;
}
}
echo $a;
A. 0
B.5
C.10
D.其他
9.http协议响应状态码中表示服务器内部错误的状态码是(D)
A.200 B.300
C.404 D.500

10.表达式(-5)%3的运行结果等于 : -2。
11. 三元运算符:条件?表达式1:表达式2;
12. substr( ‘import’ , 1,3)的结果是:mpo
13.表单提交的常用两种方式为: post 和 get 。
填空题
1.表达式(-5)%3的运行结果等于___-2____
2.三元运算符_____? :;__
3.定义常量的两种方式______define(),const__
4.substr(‘import’,1,3)的结果是__mpo

5. s t r = ” H e l l o ” , 则 str=”Hello”,则 st

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 PHP 题库测试代码实现示例: 1. 首先,需要创建一个包含题目和答案的数组: ``` $questions = array( "question1" => array( "question" => "What is the capital of France?", "answer" => "Paris" ), "question2" => array( "question" => "What is the tallest mountain in the world?", "answer" => "Mount Everest" ), "question3" => array( "question" => "What is the largest country by area?", "answer" => "Russia" ) ); ``` 2. 接下来,需要创建一个 HTML 表单,让用户输入答案: ``` <form method="post"> <?php foreach ($questions as $key => $question) { ?> <p><?php echo $question['question']; ?></p> <input type="text" name="<?php echo $key; ?>" /> <?php } ?> <input type="submit" value="Submit" /> </form> ``` 3. 在表单提交后,需要检查用户的答案是否正确,然后输出相应的结果: ``` if ($_SERVER['REQUEST_METHOD'] == 'POST') { $score = 0; foreach ($questions as $key => $question) { if (isset($_POST[$key]) && $_POST[$key] == $question['answer']) { $score++; } } echo "You scored " . $score . " out of " . count($questions); } ``` 完整的代码示例: ``` <?php $questions = array( "question1" => array( "question" => "What is the capital of France?", "answer" => "Paris" ), "question2" => array( "question" => "What is the tallest mountain in the world?", "answer" => "Mount Everest" ), "question3" => array( "question" => "What is the largest country by area?", "answer" => "Russia" ) ); ?> <form method="post"> <?php foreach ($questions as $key => $question) { ?> <p><?php echo $question['question']; ?></p> <input type="text" name="<?php echo $key; ?>" /> <?php } ?> <input type="submit" value="Submit" /> </form> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $score = 0; foreach ($questions as $key => $question) { if (isset($_POST[$key]) && $_POST[$key] == $question['answer']) { $score++; } } echo "You scored " . $score . " out of " . count($questions); } ?> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值