当前位置:网站首页>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
边栏推荐
- Differences between IPv6 and IPv4 three departments including the office of network information technology promote IPv6 scale deployment
- 【数组和进阶指针经典笔试题12道】这些题,满足你对数组和指针的所有幻想,come on !
- [detailed explanation of Huawei machine test] character statistics and rearrangement
- Two Bi development, more than 3000 reports? How to do it?
- Garbage collection mechanism of PHP (theoretical questions of PHP interview)
- "Sequelae" of the withdrawal of community group purchase from the city
- JS bright blind your eyes date selector
- Calculate weight and comprehensive score by R entropy weight method
- 【华为机试真题详解】欢乐的周末
- Using tensorboard to visualize the training process in pytoch
猜你喜欢
Interview shock 62: what are the precautions for group by?
黑马程序员-软件测试-10阶段2-linux和数据库-44-57为什么学习数据库,数据库分类关系型数据库的说明Navicat操作数据的说明,Navicat操作数据库连接说明,Navicat的基本使用,
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
P6183 [USACO10MAR] The Rock Game S
市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生
Run faster with go: use golang to serve machine learning
Creation and use of thymeleaf template
Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
MySQL之CRUD
1330:【例8.3】最少步数
随机推荐
Stm32+bh1750 photosensitive sensor obtains light intensity
mapper.xml文件中的注释
Crud de MySQL
Un week - end heureux
Ctfshow web entry command execution
用 Go 跑的更快:使用 Golang 为机器学习服务
Anaconda uses China University of science and technology source
maxcompute有没有能查询 表当前存储容量的大小(kb) 的sql?
一键更改多个文件名字
可转债打新在哪里操作开户是更安全可靠的呢
做研究无人咨询、与学生不交心,UNC助理教授两年教职挣扎史
安装配置Jenkins
黑马程序员-软件测试-10阶段2-linux和数据库-44-57为什么学习数据库,数据库分类关系型数据库的说明Navicat操作数据的说明,Navicat操作数据库连接说明,Navicat的基本使用,
useMemo,memo,useRef等相关hooks详解
计算中间件 Apache Linkis参数解读
[recruitment position] Software Engineer (full stack) - public safety direction
Ctfshow web entry information collection
Microframe technology won the "cloud tripod Award" at the global Cloud Computing Conference!
How to solve the problem of garbled code when installing dependency through NPM or yarn
Can I pass the PMP Exam in 20 days?