Home > Backend Development > PHP Tutorial > PHP Programmer Written Test and Interview Questions Sharing_PHP Tutorial

PHP Programmer Written Test and Interview Questions Sharing_PHP Tutorial

WBOY
Release: 2016-07-13 10:50:20
Original
942 people have browsed it

This article summarizes some PHP programmer written test and interview questions for you. If you are going to interview a PHP programmer, you might as well take a look at these questions first.

General PHP Programmer Written Test Questions
Tags: Programmer PHP Interview 2009-02-06 15:19
1. Use PHP to print out the time of the previous day. The printing format is May 10, 2007 22:21:21
2. The PHP code is as follows:
$a="hello";
$b=&$a;
unset($b);
$b="world";
echo $a;
The result?
3. The PHP code is as follows:
$str="cd";
$$str="landog";
$$str.="ok";
echo $cd;
The result?
4. Use PHP to write a code to exchange the values ​​of $a and $b without using the third variable, and set the initial values ​​of $a and $b yourself.
5. According to the requirements of the topic, write the code in PHP.
Table name User
ID Name Tel Content Date
1 Zhang San 13333663366 College graduate 2006-10-11
3 Zhang San 13612312331 Bachelor degree 2006-10-15
5 Zhang Si 020-5566556 Technical secondary school graduate 2006-10-15
4 Wang Wu 13521212125 College graduate 2006-12-25
2 …………
6 …………
Assume the database connection is as follows:
$mysql_db=mysql_connect("local","root","pass");
@mysql_select_db("DB",$mysql_db);
(1) Query all records whose Name is equal to "Zhang San" and output them.
(2) Query in ascending order by ID, return only the first 3 records after sorting, and output them.
6. Can JavaScript define a two-dimensional array? If not, how do you solve it?
7. Assume that a.html and b.html are in the same folder. Use JavaScript to automatically jump to b.html after opening a.html for five seconds.
8. There are two files a.html and a.php, the code is as follows:
a.html




PHP Programmer Interview







        
        


        
                                                                                                                                               

& Lt; td align = "right" & gt; mailbox: & lt;/td & gt;
                                                                                                                                                                                           


        



        

Name:
Phone:
Address:

​​​
        





a.php

$user_name = $_GET['user_name'];
$user_tel = $_GET['user_tel'];
$user_email = $_GET['user_email'];
$user_add = $_GET['user_add'];
echo "Username: $user_name
Phone: $user_tel
Email: $user_email
Address: $user_add
";
?>


(1) Please draw the display effect of a.html in the browser.
(2) Enter in a.html: username = Zhang San, phone number = 020-38259977, email = sunrising@srtek.cn, address = Guangzhou Shengrui, what is the output after pressing the submit button?
9. Have you ever used version control tools? If so, please briefly describe.
10. Use the CSS style sheet to define the font size of the visited hyperlink as 14pt and the color as red.
11. Move any digit or symbol to make the equation true, 102 = 101-1. Note: It is a move, not an exchange, and the equal sign cannot be separated.
12. For regular questions, 3, 1, 4, 1, 5, 9, 2, ( ), please write the next expression in brackets according to the regular pattern.
13. For regular questions, 5, 8, -3, 5, -2, 3, -1, ( ), please write the next expression in brackets according to the regular pattern.

++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++
Answer:

1. echo date('Y-m-d H:i:s', strtotime('-1 day'));

2. hello

3.landogok

4. $a = "abcd";
$b = "1234";
echo "When initializing a=$a,b=$b
";
$a = $a . $b;
$b = strlen( $b );
$b = substr( $a, 0, (strlen($a) - $b ) );
$a = substr( $a, strlen($b) );
echo "After exchange a=$a,b=$b
";

5. (1) $sql = “select * from User where > $result = mysql_query( $sql );
while( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ){
echo $row[‘Name’];
}
(2) $sql = “select * from User order by ID asc limit 0,3”;
$result = mysql_query( $sql );
while( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ){
echo $row[‘Name’];
}
6. JavaScript does not support two-dimensional array definition. You can use arr[0] = new array() to solve the problem

7. The javascript code is as follows:
<script><br> function go2b(){<br> window.location = "b.html";<br> window.close();<br> } <br> setTimeout( "go2b()",5000 ); //Automatically execute go2b()<br> after 5 seconds </script>

8.

(1) is as follows:

Omitted. Because I am too lazy to insert pictures, if I want to see the results, I can save the code as an html file and open it with a browser to view.

(2) The output result should be:

Name:

Telephone:

Email:

Address:

Because the form is submitted using the post method, but in a.php it is read using the get method, so no value will be read.

9. Briefly

10. a:visited { font-size: 14pt; color: red; }

11. 102 = 101-1

12. The answer is 6 because ∏=3.1415926

13. The answer is 2, and the rule is n=(n-2) – |(n-1)| ,n>=3

1. In PHP, the name of the current script (excluding path and query string) is recorded in the predefined variable (1); and the previous page URL linked to the current page is recorded in the predefined variable (2 ) in //The address of this page, SCRIPT_NAME can also be: php/test.php
echo $_SERVER['PHP_SELF']."
";
//URL address of the previous page linked to the current page:
echo $_SERVER['HTTP_REFERER']."
";
//For other information, see the reference manual: Language Reference》Variables》Predefined variables
//The absolute path name of the previously executed script: D:Inetpubwwwrootphp est.php
echo $_SERVER["SCRIPT_FILENAME"]."
";
//IP address of the user browsing the current page: 127.0.0.1
echo $_SERVER["REMOTE_ADDR"]."
";
//Query string (content after the first question mark ? in the URL): id=1&bi=2
echo $_SERVER["QUERY_STRING"]."
";
//The document root directory where the currently running script is located: d:inetpubwwwroot
echo $_SERVER["DOCUMENT_ROOT"]."
";
?>

2. Execute the program segment will output __.
//Reference Manual》Language Reference》Operator》Arithmetic Operator》% is the modulo operation, output 0
echo 8%(-2)."
";
//The result of modulo $a % $b when $a is negative is also negative. Output -2
echo ((-8)%3)."
";
//Output 2
echo (8%(-3))."
";
?>
3. In HTTP 1.0, the meaning of status code 401 is ____; if the prompt "File not found" is returned, the header function can be used, and its statement is ____.
Answer: 401 means unauthorized; header("HTTP/1.0 404 Not Found"); [See Reference Manual》Function Reference》HTTP Function》header]
4. The function of array function arsort is ____; the function of statement error_reporting(2047) is ____.
Answer: arsort: reverse sort the array and maintain the index relationship. The function of error_reporting(2047) is: report All errors and warnings
5. Write a regular expression to filter all JS/VBS scripts on the web page (that is, remove the script tag and its content):
$script="The following content will not be displayed:";
echo preg_replace("/].*?>.*?/si", "Replacement content", $script);
?>
6. Install PHP as an Apache module. In the file http.conf, first use the statement ____ to dynamically load the PHP module,
Then use the statement ____ to cause Apache to process all files with the extension php as PHP scripts.
Answer: LoadModule php5_module "c:/php/php5apache2.dll";AddType application/x-httpd-php .php
See Reference Manual》Contents》II. Installation and Configuration》6. Installation under Windows System》Apache 2.0.x under Microsoft Windows
7. Both the statements include and require can include another file into the current file. The difference between them is ____; in order to avoid including the same file multiple times, you can use the statement ____ instead.
Answer: When handling failure, include() generates a warning and require() results in a fatal error; require_once()/include_once()
8. The parameter of a function cannot be a reference to a variable, unless ____ is set to on in php.ini.
Answer: allow_call_time_pass_reference boolean: Whether to enable forcing parameters to be passed by reference when calling functions, see Appendix G of the Reference Manual
9. The meaning of LEFT JOIN in SQL is __, if tbl_user records the student’s name (name) and student number (ID),
tbl_score records the student number (ID), test score (score), and test subject (subject) of the students (some students were expelled after taking the exam and there is no record of them). If you want to print out the names of each student and the corresponding subjects For the total score, you can use the SQL statement____.
Answer: Natural left outer join
create database phpinterview;
use phpinterview
create table tbl_user
(
ID                                                                                                                                                                                                                         through int                                   not null,
name varchar(50) not null,
primary key (ID)
);
create table tbl_score
(
ID                                                                                                                                                                                                                         through int                                   not null,
Score dec (6,2) not null,
subject varchar(20) not null
);
insert into tbl_user (ID, name) values ​​(1, 'beimu');
insert into tbl_user (ID, name) values ​​(2, 'aihui');
insert into tbl_score (ID, score, subject) values ​​(1, 90, '中文');
insert into tbl_score (ID, score, subject) values ​​(1, 80, 'math');
insert into tbl_score (ID, score, subject) values ​​(2, 86, 'math');
insert into tbl_score (ID, score, subject) values ​​(2, 96, '中文');
select A.id,sum(B.score) as sumscore
from tbl_user A left join tbl_score B
on A.ID=B.ID
group by A.id
10. In PHP, heredoc is a special string whose end mark must be ____
Answer: The line where the end identifier is located cannot contain any other characters except ";"
11. Write a function that can traverse all files and subfolders in a folder.
function my_scandir($dir)
{
$files=array();
If(is_dir($dir))
{
           if($handle=opendir($dir))
             {
​​​​​​while(($file=readdir($handle))!==false)
                 {
If($file!="." && $file!="..")
                                                 {
If(is_dir($dir."/".$file))
                                                                {
$files[$file]=my_scandir($dir."/".$file);
                    }
                    else
                                                                {
$files[]=$dir."/".$file;
                    }
                 }
            }
             closedir($handle);
                 return $files;
                                                                        }  
}
print_r(my_scandir("D:Program FilesInternet ExplorerMUI"));
?>

1.Which of the following sentences will not add John to the users array?
$users[] = 'john';
Successfully added John to the users array.
array_add($users,’john’);
Function array_add() is not defined.
array_push($users,‘john’);
Successfully added John to the users array.
$users ||= 'john';
Syntax error.
2.What are the differences between sort(), assort(), and ksort()? Under what circumstances are they used?
sort()
Sort in alphabetical order according to the values ​​of the elements in the array, and the index keys will be renumbered from 0 to n-1. Mainly used to sort the array when the value of the array index key is irrelevant.
assort()
PHP does not have assort() function, so it may be a typo in asort().
asort()
Like sort(), the elements of the array are arranged in English alphabetical order. The difference is that all index keys are retained, which is especially suitable for sorting associative arrays.
ksort()
Sort in English alphabetical order according to the value of the index key in the array. It is especially suitable for associative arrays where you want to sort the index keys.
3. What will the following code produce? Why?
$num =10;
function multiply(){
$num =$num *10;
}
multiply();
echo $num;
Since the function multiply() does not specify $num as a global variable (such as global $num or $_GLOBALS['num']), the value of $num is 10.
4. What is the difference between a reference and a regular variable? How to pass by reference? Under what circumstances do we need to do this?
Reference passes the address of the variable rather than its value, so when the value of a variable is changed in a function, the entire application sees the new value of the variable.
What a regular variable passes to a function is its value. When the function changes the value of the variable, only the function sees the new value. Other parts of the application still see the old value.

$myVariable = "its' value";
Myfunction(&$myVariable); // Pass parameters by reference. Passing parameters by reference to the function can make the variables changed by the function retain the new value even after the function ends.
5. What functions can be used to insert function libraries into the currently executing script?
Different understandings of this question will lead to different answers. My first idea is to insert the PHP function library, which is nothing more than include(), include_once(), require(), require_once(), but think about it carefully, " "Library" should also include com objects and .net libraries, so our answer should also include com_load and dotnet_load respectively. Don't forget these two functions next time someone mentions "library."
6.What is the difference between foo() and @foo()?
foo() will execute this function, and any interpretation errors, syntax errors, and execution errors will be displayed on the page.
@foo() will hide all the above error messages when executing this function.
Many applications use @mysql_connect() and @mysql_query to hide mysql error messages. I think this is a serious mistake because errors should not be hidden. You must handle them properly and resolve them if possible.
7. How do you debug PHP applications?
I don't do this very often, I've tried a lot of different debugging tools and setting them up on a Linux system is not easy at all. But below I will introduce a debugging tool that has attracted much attention recently.
PHP - Advanced PHP Debugger or PHP - APD, the first step is to install it by executing the following command:
After pear install apd is installed, add the following statement at the beginning of your script to start debugging:
apd_set_pprof_trace(); After execution, open the following file to view the execution log:
apd.dumpdir
You can also use pprofp to format the log.
Detailed information can be found at http://us.php.net/manual/en/ref.apd.php.
8.What is "==="? Give an example where "==" is true but "===" is false.
"===" is for a function that can return a Boolean value of "false" or a function that is not a Boolean value but can be assigned a "false" value. strpos() and strrpos() are two of them. example.
The second part of the question is a bit more difficult, it's easy to think of an example where "==" is false but "===" is true, and very few examples where the opposite is true. But I finally found the following example:
if (strpos("abc", "a") == true){ // This part will never be executed because the position of "a" is 0, which converts to a Boolean value of "false"}if (strpos("abc" ", "a") === true){ // This part will be executed because "===" ensures that the value returned by the function strpos() will not be converted into a Boolean value.}
9. How would you define a class myclass that has no member functions or attributes?
class myclass{}
10.How do you generate an object of myclass?
$obj = new myclass();
11. How to access the properties of this category and change its value within a category?
Use statement: $this->propertyName, for example:
class myclass{ private $propertyName; public function __construct() { $this->propertyName = "value"; }}
12.What is the difference between include and include_once? What about require?
All three are used to insert other files into the script. Depending on whether url_allow_fopen is approved, this file can be obtained from inside or outside the system. But there are also subtle differences between them:
include(): This function allows you to insert the same file multiple times in the script. If the file does not exist, it will issue a system warning and continue executing the script.
include_once(): It has a similar function to include(). As its name suggests, the relevant file will only be inserted once during the execution of the script.
require(): Similar to include(), it is also used to insert other files into the script, but if the file does not exist, it will issue a system warning. This warning will cause a fatal error and cause the script to abort execution
13.Which of the following functions can redirect the browser to another page?
redir()
This is not a PHP function and will cause an execution error.
header()
This is the correct answer. header() is used to insert header information and can be used to redirect the browser to another page, for example:
header("Location: http://www.search-this.com/");
location()
This is not a PHP function and will cause an execution error.
redirect()
This is not a PHP function and will cause an execution error.

14. Which of the following functions can be used to open files for reading/writing?
fget()
This is not a PHP function and will cause an execution error.
file_open()
This is not a PHP function and will cause an execution error.
fopen()
This is the correct answer. fopen() can be used to open files for reading/writing. In fact, this function has many options. Please refer to php.net for details.
open_file()
This is not a PHP function and will cause an execution error.
15.What is the difference between mysql_fetch_row() and mysql_fetch_array()?
mysql_fetch_row() stores a database column in a zero-based array, with the first column at array index 0, the second column at index 1, and so on. mysql_fetch_assoc() stores a column of the database in an associative array. The index of the array is the field name. For example, my database query returns the three fields "first_name", "last_name", and "email". The index of the array is "first_name", "last_name" and "email". mysql_fetch_array() can return the values ​​of both mysql_fetch_row() and mysql_fetch_assoc().
16.What does the following code do? Please explain.
$date='08/26/2003';print ereg_replace("([0-9]+)/([0-9]+)/([0-9]+)","[url=file:/ /2///1///3%22,$date]2/1/3",$date[/url]);
This is to convert a date from MM/DD/YYYY format to DD/MM/YYYY format. A good friend of mine told me that this regular expression can be disassembled into the following statements. For such a simple expression, there is no need to disassemble it. It is purely for the convenience of explanation:
// Corresponds to one or more 0-9, followed by a slash $regExpression = "([0-9]+)/"; // Corresponds to one or more 0-9, followed by another slash $regExpression .= "([0-9]+)/";// Again corresponds to one or more 0-9$regExpression .= "([0-9]+)"; As for [url=file:// 2///1///3]2/1/3[/url] is used to correspond to brackets. The first bracket corresponds to the month, the second bracket corresponds to the date, and the third bracket corresponds to It's the year.
17. Given a line of text $string, how would you write a regular expression to remove the HTML tags in $string?
First of all, PHP has a built-in function strip_tags() to remove HTML tags. Why do you need to write your own regular expression? Okay, let’s treat this as an interview question. I will answer this:
$stringOfText = "

This is a test

";$expression = "/<(.*?)>(.*?)/"; echo preg_replace($expression, "[url=file://2/]2[/url]", $stringOfText);// Some people say you can also use /(<[^>]*>)/ $ expression = "/(<[^>]*>)/";echo preg_replace($expression, "", $stringOfText);
18.What are the differences in how PHP and Perl distinguish between arrays and hash tables?
This is why I always tell people to choose the appropriate programming language. How can you answer this question if you only use one language? This question is simple. All array variables in Perl begin with @, such as @myArray, while PHP uses $ as the beginning of all variables, such as $myArray.
As for Perl, % is used to represent a hash table, such as %myHash. There is no difference in PHP, and $ is still used, such as $myHash.
19. How do you address the stateless nature of HTTP with PHP?
The two main options are session and cookie. The way to use session is to add session_start() at the beginning of each page, and then use the $_SESSION hash table to store the session variable. As for cookies, you just need to remember one rule: call the set_cookie() function before outputting any text. In addition, just use the $_COOKIE hash table to access all cookie variables.
A less reliable method is to use the visitor's IP address, which has certain dangers.
20.What is the GD library used for?
This is probably my favorite library. GD has been built into the PHP system since version 4.3.0. This library allows you to process and display graphics files in various formats. Another common use of this library is to create graphics files. An alternative to GD is ImageMagick, but this library is not built into PHP and must be installed on the server by the system administrator.
21. Try to write several methods to output a piece of HTML code.
Well, you can use any output statement in PHP, including echo, print, and printf. Most people use echo as follows:
echo "My string $variable"; You can also use this method:
echo << HTML tags in here as well. The END; remarks must be on a line of its own, and can't contain any extra white space.END;
22. Is PHP better than Perl? Please discuss.
Let's not start a war of words over a simple question. As I always say: "Choose the language that suits the job, not the language that suits the job." I personally think that Perl is very suitable for use as a command line tool, although it is not suitable for web applications. It also has good performance on the command line, but its real strength can be fully realized on the command line. Similarly, although PHP can be used in a console environment, I personally think that it performs better in web applications. PHP has a large number of functions specifically designed for web applications, while Perl seems to be designed with the command line in mind. .
Personally, I like both languages. I often used Perl, PHP and Java during college. Unfortunately, I use C# at work, but at home I spend a lot of time practicing PHP, Perl, Ruby (currently studying) and Java. , keeping my skills knowledge up to date. A lot of people ask me about C and C++ and whether they still have a chance to play a role in my applications. My answer is basically "no". My recent work is mainly focused on web development, although C and C++ can also be used. Used to write web pages, but they are not designed for this kind of work after all. "Choose the right language for the job", if I need to write a console application to show the performance comparison of bubble sort, quick sort and merge sort , I will definitely use C/C++. If I needed to write a photo album system, I would use PHP or C# (I think .NET is better for making user interfaces than web pages).

PHP classic interview questions (serial 4)
1 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?
Answer: Passing by value only passes the value of a variable to another variable, while reference means that the two point to the same place.
2 What is the function of error_reporting in PHP?
Answer: The error_reporting() function sets the error_reporting directive at runtime. PHP has many levels of errors, using this function sets that level for the duration (runtime) of your script.
3 Please use regular expression (Regular Expression) to write a function to verify whether the format of the email is correct.
Answer:
if(isset($_POST['action']) &&
$_POST['action']=='submitted')
{
$email=$_POST['email'];
If(!preg_match("/^(?:w+.?)*w+@(?:w+.?)*w+$/",$email))
{
echo
"Email detection failed";
}
else
{
echo
"Email detection successful";
}
}
else
{
?>

EMAIL detection




Email: />

/>
/>
/>



}
?>

4 Briefly describe how to get the current execution script path, including the obtained parameters.
echo
"http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
//echo "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
?>

5 There is a one-dimensional array that stores integer data. Please write a function to arrange them in order from large to small. High execution efficiency is required. and explain how to improve execution efficiency. (This function must be implemented by yourself, PHP functions cannot be used)

function BubbleSort(&$arr)
{
$cnt=count($arr);
$flag=1;
for($i=0;$i<$cnt;$i++)
          {
             if($flag==0)
              {
              return;
          }
           $flag=0;
for($j=0;$j<$cnt-$i-1;$j++)
              {
If($arr[$j]>$arr[$j+1])
                   {
                     $tmp=$arr[$j];
$arr[$j]=$arr[$j+1];
                       $arr[$j+1]=$tmp;
                     $flag=1;
              }
          }
}
}
$test=array(1,3,6,8,2,7);
BubbleSort($test);
var_dump($test);
?>


6 Please give an example of what methods you use to speed up page loading during your development process
Answer: Open only when server resources are needed, close server resources in time, add indexes to the database, and pages can generate static, pictures and other large files on a separate server. Use code optimization tools

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632660.htmlTechArticleThis article summarizes some PHP programmer written test and interview questions for you, if you are preparing to interview PHP Programmers might as well take a look at these questions first. Ordinary PHP Programmer Written Test Questions Tags...
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