转载-php试题

Jun 23, 2016 pm 02:32 PM

1.  写出下列代码的结果:
                $a="Hello World!";
            $b=$a;
            print("\$b=$b
");
            print('$a=$a
');
   ?>

$b=Hello World!
$a=$a
      //'\'是逃逸符,屏蔽紧跟在后面的单个特殊字符的特殊用法
                                                          //''单引号对,屏蔽包含在内的几乎所有的特殊字符的特殊含义,除了本身
                                                          //另外,在命令行下调试这些代码,
是不会作为换行输出的~ 如果在browser,另当别论

2.  写出下列代码输出结果:
                $a="First";
            $b=&$a;
            $c=$a;
            $a="Second";
            print("$a,$b,$c
");
   ?>

Second,Second,First
              //$b是$a的引用赋值,所以$a的变化就是$b的变化
                                                      //$c可以看作$a复制一次以后的副本,所以是不相干的两个变量,因此,$a的改变不影响$c
   
3.  写出下列代码输出结果:
                 $a=2;
             $b="1.2SBC3";
             $c="EFG";
             $result1=$a.$b;
             $result2=$a*$b;
             $result3=$a*$c;
             print("$result1,$result2,$result3
");
    ?>

21.2SBC3,2.4,0
               //$result1是字符串的连接,btw,如果这题是2.$b,那系统会报error
                                                //$result2是数字的乘法,php中会自动舍弃第一个不是数字的字符开始后面的字符
                                                 //$result3是数字的乘法,与2不同的是,$c中没有任何数字型字符,因此整体被强行转换为数值型,也就是0,然后再和$a=2相乘,最后结果就是0

4.  下列不正确的变量名是:
    A. $_test    B. $2abc    C. $Var    D. $%Var

b

5.  语句for($k=0;$k=1;$k++);和语句for($k=0;$k==1;$k++);执行的次数分别是:
    A. 无限和0   B. 0和无限   C.都是无限   D. 都是0

A

/**
* 这里要重点讲一下这题,这里选择A应该是没问题,人所皆知
* 问题在于,如果第一句话改一下,变成for($k=0;$k=0;$k++);,那么循环体会被执行的次数呢?
*
* 答案是0
*
* 原因是for(expr A; expr B; expr C)在判断是否要执行循环体时,我们关心的是表达式expr B的真值。
* 注意!$k=0这个表达式的值是0!而不是可能的复制成功返回的1!
* 所以,for循环的循环判断条件为永假,自然就不会执行循环体了~~~
*
* :)
**/


6.  php函数不支持的功能有:
    A. 可变的函数名称    B. 可变的参数个数   C. 通过引用传递参数
    D. 通过指针传递参数   E. 实现递归函数

d

7.  下列对php中类的描述,不正确的是:
    A. 支持单一继承  B. 支持多继承  C. 不支持构造函数  D.不支持析构函数   
    E.必须使用$this指针来引用成员变量

b 多继承好像是要用到接口

8.  找出下列代码中的错误并修正:
                 $a[0]=""Ryan;
             $b["value"]=785.9;
             $c["blue"][0]="Ada";
             print("$a[0],$b["value"],$c["blue"][0]
");
     ?>

                 $a[0]="Ryan";
             $b["value"]=785.9;
             $c["blue"][0]="Ada";
             print("$a[0]"."$b[value]"."{$c[blue][0]}"."
");
     ?>

//引号没什么好说的
//还有关键是最后一行的$c[blue][0],如果不用花括号括起来,那么系统会自动先变量替换$c[blue],问题是这个值不存在,所以,替换完毕后的xxxx[0]也就没有了,所以会报错。这就是所谓的变量数组


9.  请按照由高到低的顺序写出下列操作符的优先级:
      and,=,>,+,~

~ + > = and 我猜的

10. 试述isset()和empty()的区别


isset()
测试变量是否存在

empty()
测试变量是否为空

在php这样的对变量定义不严格的语言中
如果一个变量从没有声明过,那么isset==false|empty==true
如果一个变量已声明,但赋值为NULL,那么和前一种情况一样
如果一个变量已声明,但赋值为'',那么isset==true|empty==true
如果一个变量已声明,且正常赋值,那么isset==true|empty==false

example as follow:

$b = NULL;
$c = '';
$d = 'str';
echo isset($a)."a\n";
echo empty($a)."b\n";
echo isset($b)."c\n";
echo empty($b)."d\n";
echo isset($c)."e\n";
echo empty($c)."f\n";
echo isset($d)."g\n";
echo empty($d)."h\n";
?>

11. 请用尽可能少的语句实现对输入Email地址进行验证的功能.

eregi('^[_a-z0-9]+(\.[_a-z0-9-]+)*@[a-z0-9]+(\.[a-z0-9-]+)*$',$emailaddress)

12. 写一算法,将下列数组按升序排序,并写出排序算法名称:
     $arrVar=array(64,29,1,43,30,9,39,75,4,11)

冒泡排序,过程略

13. 写一段程序,将文本文件中的每一个单词的首写字母转换成大写,并保存回原文件.
      提示:将串中的单词首字母转换成大写的函数:  string ucwords(string str)



14. 请写出php访问MYSQL数据库的几种方式,并做简要介绍.

15. 请写出PHPSession的实现方法;介绍你认为最好的实现方法,并说明理由.
      提示:SessionID的传递方式,Session变量的存储方法等.

16. PHP程序会有什么漏洞?

我就是最大的漏洞……


不知道对不对~~ 呵呵~~ 发现概念性的东西还是挺纠缠不清的~~
字多的慢慢再写~~~:)

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

See all articles