PHP interview questions summary sharing

小云云
Release: 2023-03-22 09:48:02
Original
1432 people have browsed it

This article mainly shares with you a summary of PHP interview questions, hoping to help everyone.

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 of the protocol?

1. The http stateless protocol cannot distinguish whether the user is coming from the same website. Yes, 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, and each read 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, requested Content has been moved to a new location 403: Access Forbidden 500: Server Internal Error 401 means Unauthorized.

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

Tar.gz:

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

Extract: tar xzf file.tar.gz

Bz2:

Package: bzip2 [-k] file

Extract: bunzip2 [-k] file

Gzip (only for files, not retaining the original file)

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 the data type (int char varchar datetime text) means; what is the difference between varchar and char?

Int Integer char Fixed-length character Varchar Variable-length character Datetime Datetime type Text Text type The difference between Varchar and char char is a fixed-length character type. How much space is allocated will occupy as much space. 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 , generate a constant SID. 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, it will store the existing SESSIONID.

8. Differences between isset() and empty()

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. It is false. Only one variable can be passed. If it is empty, it returns false. real.

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, Just exchange these two records. 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.

// 冒泡排序法
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 reflect these modifications outside the function

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.

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 can be universal. You can call the PHP built-in function (array_multisort())

//二维数组排序, $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 characters The string 'Apple Orange BananaStrawberry' forms an array $fruit,

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

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 numbers greater than 0 and English commas. Please use regular expressions to verify. If $string does not meet the requirements, an error message will be returned.

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 failed to start, row What is the wrong idea?

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


PHP session extension default Where to store session data? 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 coding, what is the following program output result? 17(utf8)

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 ()----Return the difference array of two arrays

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

array_search()----Search for the given in the array The 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 the elements in the original array, create a new array and return

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

Several methods and functions for php to read file content?

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? Enter 111?

if( ! $str ) { echo 111; }

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

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

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

What PHP forum systems are you familiar with?

Discuz

What PHP mall systems are you familiar with?

Ecshop

What PHP development frameworks are you familiar with?

Brophp,thinkphp

Tell me about your understanding of caching technology?

1. Caching technology is to cache dynamic content into files, and access dynamic pages within a certain period of time to directly call the cached files without having to revisit the database.

2. Use memcache for caching.

What design patterns do you know?

Factory mode, strategy mode, single element mode, observer mode, command chain mode

Tell me about your understanding of code management? Which code version control software do you often use?

Usually a project is developed by a team. Everyone submits their own code to the version server, and the project leader manages it according to the version, which facilitates version control, improves development efficiency, and ensures that when needed Can go back to the old version.

Commonly used version controller: SVN

Tell me what you know about SVN? Advantages and Disadvantages?

SVN is a version controller. Code developed by programmers is submitted to the version server for centralized management.

Advantages of SVN: centralized management of code, easy version control, relatively simple operation, and convenient permission control.

Disadvantages: You cannot modify the server project folder at will.

How to find the path of PHP.ini?

Generally in the installation directory of php, or in the windows directory of the window system.

PHP acceleration mode/extension? PHP debugging mode/tool?

Zend Optimizer acceleration extension

Debugging tool: xdebug

Mysql commands you commonly use?

Show databases

Show tables

Insert into table name()values()

Update table name set field=value where ...

Delete from table name where ...

Select * from table name where condition order by ... Desc/asc limit ... Group by ... Having ...

What is the command to enter the mysql management command line?

Mysql -uroot -p Enter password

show databases; What does this command do?

Show which databases are in the current mysql server

show create database mysql; What is the role of this command?

Show the sql statement that creates the database

show create table user; What is the role of this command?

Display the sql statement that creates the table

desc user; What is the role of this command?

Query the structure of the user table

explain select * from user; What is the role of this command?

Get select related information

show processlist; What is the role of this command?

Show which threads are running

SHOW VARIABLES; What does this command do?

Show system variables and values

SHOW VARIABLES like ’%conn%’; What does this command do?

显示系统变量名包含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;)
<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>
用javascript取得一个input的值?取得一个input的属性?
document.getElementById(‘name’).value;
document.getElementById(‘name’).type;
用Jquery取得一个input的值?取得一个input的属性?
$(“input[name=&#39;aa&#39;]“).val();
$(“input[name=&#39;aa&#39;]“).attr(‘type’);
请您写一段ajax提交的js代码,或者写出ajax提交的过程逻辑。
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对象

Interface B{... }

Interface C{... }

Class Aimplements B,C{ ... }

相关推荐:

PHP面试题之算法题

php面试题中面向对象的题目分析

最让人容易出错的10道php面试题

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

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template