Home Backend Development PHP Tutorial Summary of php interview questions

Summary of php interview questions

Apr 21, 2018 am 10:27 AM
php Summarize

The content introduced in this article is a summary of PHP interview questions, which has a certain reference value. Now I share it with everyone. Friends in need can refer to it

Related recommendations: "2019 Summary of PHP interview questions (collection)

1. What is object-oriented? What are the main features?

Object-oriented is a design method for programs, which helps improve the reusability of programs and makes the program structure clearer. Main features: encapsulation, inheritance, polymorphism.

2. What is the difference between SESSION and COOKIE? Please explain the reasons and functions from the protocol?

1. http is stateless The protocol cannot distinguish whether the user comes from the same website. The same user requesting different pages cannot be regarded as the same user.

2. SESSION is stored on the server side, and COOKIE is stored on the client side. Session is relatively secure. Cookies can be modified by certain means and are not safe. Session relies on cookies for delivery.

After disabling cookies, the session cannot be used normally. Disadvantages of Session: It is saved on the server side. Every time it is read, it is read from the server, which consumes resources on the server. Session is saved in a file or database on the server side. It is saved in a file by default. The file path is specified by session.save_path in the PHP configuration file. Session files are public.

3. What do the 302, 403, and 500 codes in the HTTP status mean?

One, two, three, four and five principles: 1. Message series 2. Success series 3. Redirect series 4. Request error series 5. Server-side error series

302: Temporary transfer successful , the requested content has been moved to a new location 403: Access Forbidden 500: Server Internal Error 401 represents unauthorized.

4. The command to create a compressed package and decompress the package under Linux

Tar.gz:

Packaging:tar czf file.tar.gz file.txt

Decompression: tar xzf file.tar.gz

Bz2:

Packaging: bzip2 [-k] File

Decompression: bunzip2 [-k] file

Gzip (only for files, the original file is not retained)

Packaging: gzip file1.txt

Decompression: gunzip file1. txt.gz

Zip: -r Pack directory

: zip file1.zip file1.txt

Decompress: unzip file1.zip

5. Please write down the meaning of data type (int char varchar datetime text); what is the difference between varchar and char?

Int Integer char fixed-length character Varchar variable-length character Datetime date and time type Text text type The difference between Varchar and char char is a fixed-length character type. How much space is allocated, How much space does it take up. Varchar is a variable-length character type. It takes up as much space as the content is, which can effectively save space. Since the varchar type is variable, the server has to perform additional operations when the data length changes, so the efficiency is lower than that of the char type.

6. What are the basic differences between MyISAM and InnoDB? How is the index structure implemented?

The MyISAM type does not support transactions and table locks, and is prone to fragmentation. It needs to be optimized frequently and has faster reading and writing speeds, while the InnoDB type supports transactions, row locks, and has crash recovery capabilities. Read and write speeds are slower than MyISAM.

Create index: alerttable tablename add index (`field name`)

7. Send a cookie to the client without using cookies.

Understanding: When session_start() is turned on, a constant SID is generated. When COOKIE is turned on, this constant is empty. When COOKIE is turned off, the value of PHPSESSID is stored in this constant. By adding a SID parameter after the URL to pass the value of SESSIONID, the client page can use the value in SESSION. When the client opens COOKIE and the server opens SESSION. When the browser makes the first request, the server will send a COOKIE to the browser to store the SESSIONID. When the browser makes the second request, the existing

8. isset() and empty( ) Difference

Isset determines whether the variable exists. You can pass in multiple variables. If one of the variables does not exist, it returns false. empty determines whether the variable is empty and false. Only one variable can be passed. If Returns true if empty or false.

9. How to pass variables between pages (at least two ways)? GET, POST, COOKIE, SESSION, hidden form

1. Write a regular expression that matches the URL.

'/^(https?|ftps?):\/\/(www)\.( [^\.\/] )\.(com|cn|org)(\/[\w-\.\/\?\%\&\=]*)?/i'

2. Please write down a common sorting algorithm, and use PHP to implement bubble sorting, and sort the array $a = array() from small to large.

Common sorting algorithms: bubble sort, quick sort, simple selection sort, heap sort, direct insertion sort, Hill sort, merge sort.

The basic idea of ​​the bubble sorting method is: perform multiple scans from back to front (reverse order) on the keywords of the records to be sorted. When it is found that the order of two adjacent keywords does not match the rules required for sorting, these will be Two records are exchanged. In this way, records with smaller keywords will gradually move from back to front, just like bubbles floating upward in water, so this algorithm is also called bubble sorting method.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

// 冒泡排序法

Function mysort($arr){

         For($i=0;$i<count($arr); $i++){

                  For($j=0; $j<count($arr)-1-$i; $j++){

                           If($arr[$j]> $arr[$j+1]){

                                    $tmp=$arr[$j];

                                    $arr[$j]=$arr[$j+1];

                                    $arr[$j+1]=$tmp;

            }

       }

   }

         Return$arr;

}

$arr=array(3,2,1);

print_r(mysort($arr));

Copy after login

3. Please explain the difference between passing by value and passing by reference in PHP. When to pass by value and when to pass by reference?
Pass by value: Any changes to the value within the function scope will be ignored outside the function

Pass by reference: Any changes to the value within the function scope will also be reflected outside the function Modify

Advantages and Disadvantages: When passing by value, PHP must copy the value. Especially for large strings and objects, this can be a costly operation. Passing by reference does not require copying the value, which is good for improving performance.


What is the function of error_reporting in PHP?
Set the error level of PHP and return to the current level.


Please use regular expression (Regular Expression) to write a function to verify whether the format of the email is correct.

1

2

3

4

5

6

7

8

if(isset($_POST[&#39;action&#39;]) && $_POST[&#39;action&#39;]==’submitted’){

         $email=$_POST[&#39;email&#39;];

         if(!preg_match(“/^[0-9a-zA-Z-]+@[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+){1,3}$/”,$email)){

                  echo“电子邮件检测失败”;

         }else{

                  echo“电子邮件检测成功”;

         }

}

Copy after login

Write a two-dimensional array sorting algorithm function that is versatile and can call the PHP built-in function (array_multisort())

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

//二维数组排序, $arr是数据,$keys是排序的健值,$order是排序规则,1是升序,0是降序

function array_sort($arr, $keys, $order=0) {

         if(!is_array($arr)) {

                  return false;

         }

         $keysvalue =array();

         foreach($arr as$key => $val) {

                  $keysvalue[$key] = $val[$keys];

         }

         if($order == 0){

                  asort($keysvalue);

         }else {

                  arsort($keysvalue);

         }

         reset($keysvalue);

         foreach($keysvalueas $key => $vals) {

                  $keysort[$key] = $key;

         }

         $new_array =array();

         foreach($keysortas $key => $val) {

                  $new_array[$key] = $arr[$val];

         }

         return $new_array;

}

Copy after login

Please use spaces as intervals to split the string 'Apple Orange BananaStrawberry' into an array $fruit,

* array All elements in are in lowercase letters and sorted in alphabetical order

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

class sort {

         private $str;

         public function__construct($str) {

                  $this->str=strtolower($str);

         }

         private functionexplodes() {

                  if(empty($this->str)) returnarray();

                  $arr=explode("",$this->str);

                  return is_array($arr)?$arr:array($arr);

         }

         public functionsort() {

                  $explode=$this->explodes();

                  sort($explode);

                  return $explode;

         }

}

$str=&#39;Apple Orange Banana Strawberry&#39;;

$sortob=new sort($str);

var_dump($sortob->sort());

Copy after login

For the user to input a string $string, it is required that $string can only contain For numbers and English commas greater than 0, please use regular expressions to verify. If $string does not meet the requirements, an error message will be returned

1

2

3

4

5

6

7

8

9

10

11

12

13

14

class regx {

         public staticfunction check($str) {

         if(preg_match("/^([1-9,])+$/",$str)){

                  return true;

         }

         return false;

         }

}

$str="12345,6";

if(regx::check($str)) {

echo "suc";

} else {

echo "fail";

}

Copy after login

Windows platform, Apache Http Server fails to start, what are the troubleshooting ideas?

Check whether port 80 used by apache is occupied. If it is occupied, stop occupying port 80 first. service, and then start the apache server


Where does the PHP session extension store session data by default? D

A) SQLite Database

B) MySQL Database

C) Shared Memory

D) File System

E) Session Server

If you want To automatically load a class, which of the following function declarations is correct? C

A) function autoload($class_name)

B) function __autoload($class_name, $file)

C) function __autoload($class_name)

D) function _autoload($class_name)

E) function autoload($class_name, $file)

PHP program uses utf-8 encoding, what is the output result of the following program? B
$str = 'hello hello world';

echo strlen ($str);

What php array-related functions do you know?

array()----Create an array

array_combine()----Create a new array by merging two arrays

range() ----Create and return an array containing elements in the specified range

compact()----Create an array

array_chunk()----Split an array into multiple

array_merge()----Merge two or more arrays into one array

array_slice()----Remove a value from the array based on conditions

array_diff()----Returns the difference array of two arrays

array_intersect()----Calculate the intersection of arrays

array_search()----In the array Search for a given value

array_splice()----Remove part of the array and replace it

array_key_exists()----Determine whether the specified key exists in an array

shuffle()----Rearrange the elements in the array in random order

array_flip()----Exchange the keys and values ​​in the array

array_reverse( )----Reverse the order of elements in the original array, create a new array and return

array_unique()----Remove duplicate values ​​in the array

Several methods and functions for reading file contents in php?

Open the file and read it. Fopen()fread()

Open and read once and complete file_get_contents()

In the following program, what is the value of the variable str and enter 111?

if( ! $str ) { echo 111; }

The value in $str is: 0, '0′, false, null,""

What are some PHP technologies you know (smarty, etc.)?

Smarty,jquery,ajax,memcache,p css,js,mysqli,pdo,svn,thinkphp,brophp,yii

What you have What are the familiar PHP forum systems?

Discuz

你所熟悉的PHP商城系统 有哪些?

Ecshop

你所熟悉的PHP开发框架 有哪些?

Brophp,thinkphp

说说你对缓存技术的了解?

1、缓存技术是将动态内容缓存到文件中,在一定时间内访问动态页面直接调用缓存文件,而不必重新访问数据库。

2、使用memcache可以做缓存。

你所知道的设计模式有哪些?

工厂模式、策略模式、单元素模式、观察者模式、命令链模式

说说你对代码管理的了解?常使用那些代码版本控制软件?

通常一个项目是由一个团队去开发,每个人将自己写好的代码提交到版本服务器,由项目负责人按照版本进行管理,方便版本的控制,提高开发效率,保证需要时可以回到旧版本。

常用的版本控制器:SVN

说说你对SVN的了解?优缺点?

SVN是一种版本控制器,程序员开发的代码递交到版本服务器进行集中管理。

SVN的优点:代码进行集中管理,版本控制容易,操作比较简单,权限控制方便。

缺点:不能随意修改服务器项目文件夹。

怎么找到PHP.ini的路径?

一般都在php的安装目录下,或者window系统的windows目录下。

PHP加速模式/扩展? PHP调试模式/工具?

Zend Optimizer加速扩展

调试工具:xdebug

你常用到的mysql命令?

Show databases

Show tables

Insert into 表名()values()

Update 表名 set字段=值 where ...

Delete from 表名where ...

Select * from 表名where 条件 order by ... Desc/asc limit ... Group by ... Having ...

进入mysql管理命令行的命令?

Mysql -uroot -p回车密码

show databases; 这个命令的作用?

显示当前mysql服务器中有哪些数据库

show create database mysql; 这个命令的作用?

显示创建数据库的sql语句

show create table user; 这个命令的作用?

显示创建表的sql语句

desc user; 这个命令的作用?

查询user表的结构

explain select * from user; 这个命令的作用?

获取select相关信息

show processlist; 这个命令的作用?

显示哪些线程正在运行

SHOW VARIABLES; 这个命令的作用?

显示系统变量和值

SHOW VARIABLES like ’%conn%’; 这个命令的作用?

显示系统变量名包含conn的值

LEFT JOIN 写一个SQL语句?

SELECTA.id,A.class FROM A LEFT JOIN B ON A.cid=B.id

in, not ni, exist, not exist的作用和区别?

in在什么中

Not in 不在什么中

Exists 存在

Not exists 不存在

怎么找到数据库的配置文件路径?

在数据库安装目录下,my.ini

简述Linux下安装PHP的过程?

安装软件之前先安装编译工具gcc、gcc-c++

拷贝源码包,解包解压缩

Cd /lamp/php进入php目录

./configure–prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc指定安装目录和配置文件目录

Make 编译

Make install安装

简述Linux下安装Mysql的过程?

Groupadd mysql 添加一个用户组mysql

Useradd -gmysql mysql 添加一个mysql用户指定分组为mysql

Cd /lamp/mysql 进入mysql目录

./configure–prefix=/usr/local/mysql/ –with-extra-charsets=all

Make

Make all

简述Linux下安装apache的过程?

Cd /lamp/httpd 进去apache软件目录

./configure–prefix=/usr/local/apache2/ –sysconfdir=/etc/httpd/ –with-included-apr

Make

Make all

HTML/CSS/p/Javascritp:

1. 设计一个页面(4个 p 第一个p 宽960px 居中;第2-4个p 3等分960px;)

1

2

3

4

5

6

7

8

9

10

<style>

Body{Text-align:center; Margin:0; Padding:0; }

#box{Width:960px; Margin:0 auto; }

.small{Width:320px; Float:left; }

</style>

<pid=’box’>

<pclass=’small’></p>

<pclass=’small’></p>

<pclass=’small’></p>

</p>

Copy after login

用javascript取得一个input的值?取得一个input的属性?

1

2

document.getElementById(‘name’).value;

document.getElementById(‘name’).type;

Copy after login

用Jquery取得一个input的值?取得一个input的属性?

1

2

$(“input[name=&#39;aa&#39;]“).val();

$(“input[name=&#39;aa&#39;]“).attr(‘type’);

Copy after login

请您写一段ajax提交的js代码,或者写出ajax提交的过程逻辑。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

var xmlhttp;

if(window.XMLHttpRquest){

xmlhttp=newXMLHttpRequest();

}elseif(window.ActiveXObject){

xmlhttp=newActiveXObject(‘Microsoft.XMLHTTP’);

}

xmlhttp.open(‘GET’,’1.php?aa=name’,true);

xmlhttp.onreadystatechange=function(){

if(xmlhttp.readyState==4){

if(xmlhttp.status==200){

var text=xmlhttp.responseText;

}

}

}

xmlhttp.send(null);

Copy after login

简述Cookie的设置及获取过程

设置COOKIE的值:

Setcookie(名称,值,保存时间,有效域);

获取值:$_COOKIE['名称'];

面向对象中接口和抽象类的区别及应用场景?

1、有抽象方法的类叫做抽象类,抽象类中不一定只有抽象方法,抽象方法必须使用abstract关键字定义。

2、接口中全部是抽象方法,方法不用使用abstract定义。

3、当多个同类的类要设计一个上层,通常设计为抽象类,当多个异构的类要设计一个上层,通常设计为接口。

用面向对象来实现A对象继承B和C对象

1

2

3

Interface B{... }

Interface C{... }

Class Aimplements B,C{ ... }

Copy after login

相关推荐:

最全最详细的PHP面试题(带有答案)

PHP 经典面试题集 PHP 经典面试题集

The above is the detailed content of Summary of php interview questions. For more information, please follow other related articles on the PHP Chinese website!

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)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

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 do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

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.

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

See all articles