当前位置:网站首页>Common PHP interview questions (1) (written PHP interview questions)
Common PHP interview questions (1) (written PHP interview questions)
2022-07-05 15:05:00 【Back end regular developers】
List of articles
- 1. The way PHP Value transfer and reference of
- 2. Object oriented concept and understanding
- 3. Talk about dependency injection
- 4. Differences and uses between static classes and static methods
- 5. Write the following output
- 6. Please use PHP Write a function to verify whether the email format is correct ( Require regular )
- 7. <? echo “Hello CSDN”; ?> No output , What might be the reason . Briefly describe the process of solving this problem
- 8. In a function ( This function doesn't have return sentence ) Inside to deal with global variables , And change his value , There are two ways to achieve (global And quotes &)
- 9. Write a function , Can traverse all the files and subfolders under a folder .( Directory operation )
- 10. Can make HTML and PHP Separate the templates used
- 11.PHP The method of realizing infinite classification
- 12. List several things you know PHP The method of traversing or iterating the array
- 13. Enter the web address in the browser to the page display , What happened during ?
1. The way PHP Value transfer and reference of
php Pass value : Within the scope of the function , Change the value of the variable , It will not affect the variable value outside the function .
PHP By reference : Within the scope of the function , Any change to the value , It's also reflected outside the function , Because it's a memory address .
Advantages and disadvantages : It takes a lot of time to transfer values , Especially for large strings and objects , It will be a costly operation , Transfer reference , Any operation within a function is equivalent to an operation on a pass variable , High efficiency in transmitting large variables !
2. Object oriented concept and understanding
( encapsulation 、 Inherit 、 polymorphic )
3. Talk about dependency injection
PHP Principle and usage of dependency injection
4. Differences and uses between static classes and static methods
- Static class : The so-called static class means that it does not need to be instantiated into an object , Classes called directly in a static way , Suitable for making some stateless tools
- Static methods :
class Test{
const AI = "AI";
public static $a = "a";
public static function aAction(){
//TODO
}
}
Test::aAction();
Methods like this that can be called directly outside without instantiating classes are called static methods .
5. Write the following output
//(1)
$b = 100;
$c = 50;
$a = $b>$c?100:50;
echo $a; //100
//(2)
$str = “php”;
$$str = “teems”;
$$str .= “coffice”;
echo $php; //teemscoffice
//(3)
$a = “b”;
$b = “a”;
$ar[$a] = $b;
$ar[$b] = $a;
echo $ar[‘a’]; //b
//(4)
$n = 3.5;
$a = floor($n);
$b = round($n);
echo $a.$b; //34
echo $a+$b; //7
// notes :floor(): Rounding down
//round() 4 House 5 Rounding in
//$a=3;$b=4;
6. Please use PHP Write a function to verify whether the email format is correct ( Require regular )
$gz="/^[0-9a-z]+([-_.][0-9a-z]+)*@([0-9a-z]+\.[a-z]{2,14}(\.[a-z]{2,3})?)$/i";
$email = "[email protected]";
if(preg_match($gz,$email)){
echo " The format is correct ";
}else{
echo " Wrong format ";
}
7. <? echo “Hello CSDN”; ?> No output , What might be the reason . Briefly describe the process of solving this problem
Maybe there is no short tag on the server short_open_tag = Set to Off,php.ini Open the short label control parameters : short_open_tag = On
8. In a function ( This function doesn't have return sentence ) Inside to deal with global variables , And change his value , There are two ways to achieve (global And quotes &)
// Use Global
$var = 1;
function get_pra(){
global $var;
$var = "xxx";
echo $var;
}
echo $var."--";
get_pra();
echo $var;
// Use &
$var1 = 1;
function get_pra1(&$val){
$val +=1;
}
echo $var1."--";
get_pra1($var1);
echo $var1;
9. Write a function , Can traverse all the files and subfolders under a folder .( Directory operation )
listDir($dir);
function listDir($dir="./"){
if (is_dir($dir)){
$handle = opendir($dir);
while (($file = readdir($handle)) !== false){
if ($file == "." || $file == ".."){
continue;
}
if (is_dir($sub_dir = realpath($dir.'/'.$file))){
echo " Files in the folder :".$dir.":".$file.PHP_EOL;
listDir($sub_dir);
}else{
echo " The file named :".$file.PHP_EOL;
}
}
closedir($handle);
}else{
echo $dir." Not a directory ";
}
}
10. Can make HTML and PHP Separate the templates used
- Smarty
- Template
- Blade(Laravel Of )
11.PHP The method of realizing infinite classification
Recursion and reference (&)
$array = array(
array('id' => 1, 'pid' => 0, 'name' => ' Hebei Province '),
array('id' => 2, 'pid' => 0, 'name' => ' The Beijing municipal '),
array('id' => 3, 'pid' => 1, 'name' => ' Handan City '),
array('id' => 4, 'pid' => 2, 'name' => ' Chaoyang District '),
array('id' => 5, 'pid' => 2, 'name' => ' Tongzhou District '),
array('id' => 6, 'pid' => 4, 'name' => ' Wangjing '),
array('id' => 7, 'pid' => 4, 'name' => ' Jiuxianqiao '),
array('id' => 8, 'pid' => 3, 'name' => ' Yongnian District '),
array('id' => 9, 'pid' => 1, 'name' => ' Wu'an city '),
);
/** * Recursive implementation of infinite classification * @param $array Classified data * @param $pid Father ID * @param $level Classification level * @return $list An array of classes Just go through it $level Can be used to traverse indents */
function getTree($array, $pid =0, $level = 0){
// Declare a static array , Avoid recursive calls , Multiple declarations cause the array to overwrite
static $list = [];
foreach ($array as $key => $value){
// First traversal , Find the node whose parent node is the root node That is to say pid=0 The node of
if ($value['pid'] == $pid){
// The node whose parent node is the root node , The level of 0, That is, the first level
$value['level'] = $level;
// Put the array in list in
$list[] = $value;
// Remove this node from the array , Reduce the consumption of subsequent recursion
unset($array[$key]);
// Start recursion , Find parent ID For this node ID The node of , The level is the original level +1
getTree($array, $value['id'], $level+1);
}
}
return $list;
}
/* * Get the recursive data , Traversal generates classification */
$array = getTree($array);
foreach($array as $value){
echo str_repeat('--', $value['level']), $value['name'].PHP_EOL;
}
/** * Recursive reference infinite classification * @param $array Classified data * @return array An array of classes Just go through it */
function generateTree($array){
// First step Structural data
$items = array();
foreach($array as $value){
$items[$value['id']] = $value;
}
// Second parts Traversal data Generate tree structure
$tree = array();
foreach($items as $key => $value){
if(isset($items[$value['pid']])){
$items[$value['pid']]['son'][] = &$items[$key];
}else{
$tree[] = &$items[$key];
}
}
return $tree;
}
$array = generateTree($array);
var_dump($array);
12. List several things you know PHP The method of traversing or iterating the array
- For loop
<?php
for ($i=1; $i<=5; $i++)
{
echo " The number is " . $i . PHP_EOL;
}
?>
- Foreach
foreach ($array as $key => $value)
{
To execute code ;
}
- each
- list
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
reset($people);
while (list($key, $val) = each($people))
{
echo "$key => $val<br>";
}
?>
13. Enter the web address in the browser to the page display , What happened during ?

Generally speaking, it is divided into the following processes :
- DNS analysis : Resolve the domain name to IP Address
- TCP Connect :TCP Three handshakes
- send out HTTP request
- The server processes the request and returns HTTP message
- Browser parse render page
- disconnect :TCP Four waves
边栏推荐
- 手写promise与async await
- [C question set] of Ⅷ
- 做研究无人咨询、与学生不交心,UNC助理教授两年教职挣扎史
- Isn't it right to put money into the external market? How can we ensure safety?
- How to solve the problem of garbled code when installing dependency through NPM or yarn
- CPU设计相关笔记
- Differences between IPv6 and IPv4 three departments including the office of network information technology promote IPv6 scale deployment
- Talking about how dataset and dataloader call when loading data__ getitem__ () function
- CPU设计实战-第四章实践任务二用阻塞技术解决相关引发的冲突
- Ctfshow web entry command execution
猜你喜欢

Interpretation of Apache linkage parameters in computing middleware

Fr exercise topic - simple question

【jvm】运算指令

基于TI DRV10970驱动直流无刷电机

【华为机试真题详解】字符统计及重排

Install and configure Jenkins

Huiyuan, 30, is going to have a new owner

危机重重下的企业发展,数字化转型到底是不是企业未来救星

Microframe technology won the "cloud tripod Award" at the global Cloud Computing Conference!

Differences between IPv6 and IPv4 three departments including the office of network information technology promote IPv6 scale deployment
随机推荐
Change multiple file names with one click
一键更改多个文件名字
Live broadcast preview | how to implement Devops with automatic tools (welfare at the end of the article)
There is a powerful and good-looking language bird editor, which is better than typora and developed by Alibaba
[detailed explanation of Huawei machine test] happy weekend
Calculate weight and comprehensive score by R entropy weight method
CPU设计实战-第四章实践任务二用阻塞技术解决相关引发的冲突
Ecotone technology has passed ISO27001 and iso21434 safety management system certification
Photoshop插件-动作相关概念-非加载执行动作文件中动作-PS插件开发
Can I pass the PMP Exam in 20 days?
Where is the operation of convertible bond renewal? Is it safer and more reliable to open an account
想问下大家伙,有无是从腾讯云MYSQL同步到其他地方的呀?腾讯云MySQL存到COS上的binlog
Two Bi development, more than 3000 reports? How to do it?
anaconda使用中科大源
Cartoon: programmers don't repair computers!
P1451 calculate the number of cells / 1329: [example 8.2] cells
计算中间件 Apache Linkis参数解读
Ctfshow web entry command execution
How to open an account of qiniu securities? Is it safe to open an account?
Ten billion massage machine blue ocean, difficult to be a giant