当前位置:网站首页>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
边栏推荐
- 黑马程序员-软件测试-10阶段2-linux和数据库-44-57为什么学习数据库,数据库分类关系型数据库的说明Navicat操作数据的说明,Navicat操作数据库连接说明,Navicat的基本使用,
- P1451 求细胞数量/1329:【例8.2】细胞
- What are CSRF, XSS, SQL injection, DDoS attack and timing attack respectively and how to prevent them (PHP interview theory question)
- 爱可可AI前沿推介(7.5)
- P6183 [USACO10MAR] The Rock Game S
- 1330:【例8.3】最少步数
- 729. 我的日程安排表 I :「模拟」&「线段树(动态开点)」&「分块 + 位运算(分桶)」
- qt creater断点调试程序详解
- 超越PaLM!北大碩士提出DiVeRSe,全面刷新NLP推理排行榜
- R 熵权法计算权重及综合得分
猜你喜欢
超越PaLM!北大硕士提出DiVeRSe,全面刷新NLP推理排行榜
[detailed explanation of Huawei machine test] character statistics and rearrangement
基于TI DRV10970驱动直流无刷电机
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
【华为机试真题详解】字符统计及重排
Microframe technology won the "cloud tripod Award" at the global Cloud Computing Conference!
危机重重下的企业发展,数字化转型到底是不是企业未来救星
Thymeleaf uses background custom tool classes to process text
【jvm】运算指令
Fr exercise topic --- comprehensive question
随机推荐
手写promise与async await
Coding devsecops helps financial enterprises run out of digital acceleration
计算中间件 Apache Linkis参数解读
P1451 calculate the number of cells / 1329: [example 8.2] cells
Your childhood happiness was contracted by it
Coding devsecops helps financial enterprises run out of digital acceleration
CODING DevSecOps 助力金融企业跑出数字加速度
Ctfshow web entry command execution
Photoshop插件-动作相关概念-非加载执行动作文件中动作-PS插件开发
漫画:程序员不是修电脑的!
裁员下的上海
亿咖通科技通过ISO27001与ISO21434安全管理体系认证
当代人的水焦虑:好水究竟在哪里?
【C 题集】of Ⅷ
【NVMe2.0b 14-9】NVMe SR-IOV
用 Go 跑的更快:使用 Golang 为机器学习服务
【华为机试真题详解】欢乐的周末
CPU设计相关笔记
I want to inquire about how to ensure data consistency when a MySQL transaction updates multiple tables?
P1451 求细胞数量/1329:【例8.2】细胞