当前位置:网站首页>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
边栏推荐
- How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
- Super wow fast row, you are worth learning!
- [detailed explanation of Huawei machine test] happy weekend
- Stm32+bh1750 photosensitive sensor obtains light intensity
- Thymeleaf uses background custom tool classes to process text
- 【華為機試真題詳解】歡樂的周末
- 【NVMe2.0b 14-9】NVMe SR-IOV
- 【招聘岗位】软件工程师(全栈)- 公共安全方向
- Anaconda uses China University of science and technology source
- Coding devsecops helps financial enterprises run out of digital acceleration
猜你喜欢

FR练习题目---简单题
![[detailed explanation of Huawei machine test] character statistics and rearrangement](/img/0f/972cde8c749e7b53159c9d9975c9f5.png)
[detailed explanation of Huawei machine test] character statistics and rearrangement

Selection and use of bceloss, crossentropyloss, sigmoid, etc. in pytorch classification

面试突击62:group by 有哪些注意事项?

Photoshop插件-动作相关概念-ActionList-ActionDescriptor-ActionList-动作执行加载调用删除-PS插件开发

Implement a blog system -- using template engine technology

Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology

Photoshop plug-in action related concepts actionlist actiondescriptor actionlist action execution load call delete PS plug-in development

MySQL----函数

How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
随机推荐
手写promise与async await
漫画:程序员不是修电脑的!
Run faster with go: use golang to serve machine learning
P1451 calculate the number of cells / 1329: [example 8.2] cells
Change multiple file names with one click
webRTC SDP mslabel lable
CPU设计实战-第四章实践任务二用阻塞技术解决相关引发的冲突
Ctfshow web entry explosion
CPU design practice - Chapter 4 practical task 2 using blocking technology to solve conflicts caused by related problems
Under the crisis of enterprise development, is digital transformation the future savior of enterprises
机器学习框架简述
Magic methods and usage in PHP (PHP interview theory questions)
No one consults when doing research and does not communicate with students. UNC assistant professor has a two-year history of teaching struggle
Want to ask the big guy, is there any synchronization from Tencent cloud Mysql to other places? Binlog saved by Tencent cloud MySQL on cos
面试突击62:group by 有哪些注意事项?
Easyocr character recognition
做研究无人咨询、与学生不交心,UNC助理教授两年教职挣扎史
[JVM] operation instruction
[recruitment position] infrastructure software developer
[detailed explanation of Huawei machine test] character statistics and rearrangement