Summary of interview questions for about two weeks in mid-September!
1. What is the difference between echo(), print(), print_r()?
echo() is a language structure, no return value
The function of print() is basically the same as echo(), and it is also a language structure. The difference is that print has a return value, and always returns 1
print_r is a recursive print for output array objects
2. What is the difference between get and post submission method in the form?
The GET method is the default method for the form to submit data, which passes the user’s data through the URL request. The amount of data transmitted by the GET method is very small, generally limited to about 2KB, but its execution efficiency is higher than that of the POST method. Since the data transmitted using the GET method is transparent to the user, there may be some security problems. The POST method uses the HTTP POST mechanism to place the data in the form in the HTML header (Header) and pass it to the server side. Different from the GET method, the data passed by the POST method is invisible to the user, and the amount of data passed by the POST method is also relatively large.
3. What is the difference between session and cookie?
Cookies are saved on the client side, the session is saved on the server, and the session ID is saved on the client.
4. What is the transaction in the database?
An operating unit, all operations in this unit are either executed or failed. If all operations are successful, the transaction commits a commit. Even if an operation fails, the transaction will roll back, and all the affected data will be restored to the previous state.
5. How to implement string flipping?
<?php
$a = ‘abcde’;
$b = “;
for ($i=strlen($a)-1;$i>=0;$i–) {
$b .= $a{$i};
}
// or
$c = strrev($a);
?>
6. How to optimize mysql database?
Optimize queries, such as using indexes, using connection queries instead of subqueries
Optimize the database structure, such as sub-table, adding intermediate tables, adding redundant fields, analysis table, check table, optimization table
Optimize the speed of insert records, such as disable index before inserting records, insert multiple records in one insert statement
Optimize the hardware configuration of MySQL server, such as increasing memory, disk number, and improving disk read and write speed
Optimize MySQL server parameter configuration
7. Please explain the difference between the passed value and the reference in PHP, when to pass the value, and when to pass the reference?
Pass values: Variables always pass value assignments by default. When the value of a variable is assigned to another variable, changing the value of one of the variables will not affect the other variable.
Passing Reference: Changing a new variable will affect the original variable, and vice versa.
When transmitting the value, the value must be copied. For large-scale strings and objects, there is a certain performance loss, and the transmission reference does not need to copy the value, which is beneficial to the performance improvement.
8. What is the difference between mysql_fetch_row and mysql_fetch_array?
mysql_fetch_row() gets a row from the result set as an enumeration array
mysql_fetch_array() takes a row from the result set as an associative array, or a number array, or both
9. Please write the meaning of the data type (int char varchar datetime text); what is the difference between char and varchar
Int number type, char fixed length string, varchar variable length string, datetime date/time type, combination of date and time, text string of text
The length of the char is fixed to the length declared when the table is created, and when the char value is saved, fill the space on their right to reach the specified length. VARCHAR is a variable-length string, and the VARCHAR value is not filled when it is saved.
10. Please write out the PHP5 permission control modifier
Public Public Protected Private Private Private
11. Please write the constructor and destructor of php5
__construct __destruct
Find the maximum and minimum values of the three numbers $a, $b, and $c
<?php
$a = 3;
$b = 44;
$c = 40;
echo max($a, $b, $c);
echo min($a, $b, $c);
?>
13. Use php to write a simple query, find out all the contents named “Zhang San” and print them out
table name user
name tel content date
Zhang San 13333663366 Graduated from college 2006-10-11
Zhang San 13612312331 Graduated from college 2006-10-15
Zhang Si 021-55665566 College graduate 2006-10-15
Please complete the code according to the above questions:
connect_errno) {
echo("Connect failed: ", $mysqli->connect_error);
exit();
}
$query = "SELECT * FROM user WHERE name='张三'";
if ($result = $mysqli->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
echo $row['name'].' ';
echo $row['tel'].' ';
echo $row['content'].' ';
echo $row['date']. '
’;
}
/* free result set */
$result->free();
}
/* close connection */
$mysqli->close();
?>
14. How to use the following classes and explain what the following means?
Get_test($num);
?>
15. Write out the format of SQL statements: insert, update, delete
table name user
name tel content date
Zhang San 13333663366 College graduate 2006-10-11
Zhang San 13612312331 Bachelor’s degree 2006-10-15
Zhang Si 021-55665566 Graduated from technical secondary school 2006-10-15
(a) There is a new record (Xiao Wang 13254748547 High school graduation 2007-05-06) Please add to the table with sql statement
(b) Please use the sql statement to update Zhang San’s time to the current system time
(C) Please write all records named Zhang Si deleted
(a)
insert into user(‘name’, ‘tel’, ‘content’, ‘date’) values(‘Xiao Wang’,’13254748547′, ‘High school graduation’, ‘2007-05-06’)
(b)
update user set date=date_format(now(),’%y-%m-%d’) where name=’Zhang San’
(c)
delete from user where name=’Zhang Si’
16. Write the output result of the following program
<?php
$b = 201;
$c = 40;
$a = $b>$c?4:5;
echo $a;
?>
4
17. What functions can be used to prevent SQL injection?
Intval(), HtmlSpecialChars()
18. What is the garbage collection mechanism of PHP?
In PHP, when no variable points to this object, the object becomes garbage. PHP will destroy it in memory, which is the GC garbage disposal mechanism of PHP, preventing memory from overflowing.
19. What method do you use to check the execution efficiency of the PHP script (usually the script execution time) and the efficiency of the database SQL (usually the database query time), and locate and analyze the bottleneck of script execution and database query?
explain
20. Please give an example of how to speed up the loading of the page during your development process?
Backend:
Generate static html
generate xml
Use acceleration software such as Zend
Front end:
JS, CSS, image compression, merge
21. For websites with large traffic, what method do you use to solve the problem of traffic?
1. Use flow analysis statistical software;
2. Confirm whether the server hardware is enough to support the current traffic;
3. Optimize database access;
4. External hotlinking is prohibited;
5. Control the download of large files;
6. Use different hosts to divert the main traffic;
7. Squid[反向代理], the best choice;
8. Increase the bandwidth;
22. Please write down the three characteristics of object-oriented?
Encapsulation Inheritance Polymorphism
23. Please talk about MVC
The goal of MVC is to separate business logic from the consideration of the user interface. In the MVC, the model (model) represents information (data) and business rules; the view (view) contains user interface elements, such as text, forms, etc.; the controller (controller) manages the communication in the model and the view.
24. Have you used the design pattern, please list it?
Factory Mode Single Element Mode Observer Mode Command Chain Mode Strategy Mode
25. Writing Bubble Sorting Algorithm
=$i;$j–) {
if ($arr[$j]<$arr[$j-1]) { $temp = $arr[$j-1]; $arr[$j-1] = $arr[$j]; $arr[$j] = $temp; } } } ?>
26. Write a function, as efficiently as possible, take out the extension of the file from a standard URL
27. What is the difference between sort(), asort(), and ksort()? Under what circumstances are they used?
sort() sorts the array, when the function ends, the array unit will be rearranged from the lowest to the highest
asort() sorts the array and keeps the index relationship
ksort() sorts the array by key name
28. What is the following code output? Why?
<?php
$num = 10;
function multiply() {
$num = $num * 10;
}
multiply();
echo $num;
?>
Because $num in the function is not defined, and its scope is within the function
29. Execute block <?php echo 8%(-2) ?> What will be output
0
30. What is the difference between reference and a regular variable? How to pass by reference? Under what circumstances do we need to do this?
Reference transmits the address of the variable instead of its value
<?php
$var =aad;
//MyFunction(&$var); //Pass by Reference
?>
Transfer parameters to the function with reference, the variable that can make the function change, even after the end of the function, the new value is reserved
31. What is the difference between foo() and @foo()?
Foo() will display an error message when an error occurs
@foo() hides the error message when an error occurs
32. Explain “===” and “==” respectively
== Determine whether the values are equal
=== Determine whether the values are equal and require the same type
33. What is the difference between include and include_once? How about require?
INCLUDE_ONCE If the file has been included, it will not be included again
require_once if the file has been included, it will not be included again
<?php
define(__root__, dirname(dirname(__file__)));
//require_once(__root__./1.php);
//require_once(__root__./1.php);
?>
34. Which function in redir(), herder(), location(), and redirect() can go to another page in anti-browser?
header()
35. Which function in fget(), file_open(), fopen(), open_file() can be used to open files for reading/writing?
fopen()
36. How do you use PHP to solve the stateless nature of HTTP?
session cookie
37. What is the GD function library used for?
processing pictures
38. The parameter of a function cannot be a reference to the variable, unless ____ is set to on in php.ini?
ALLOW_CALL_TIME_PASS_REFERENCE
39. Write a function, as efficiently as possible, iterate through all the subfolders in the folder ‘home’, and return an array of subfolder names
<?php
function my_scandir($dir) {
$files = array();
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[]= $file;
}
}
}
}
return $files;
}
$result = my_scandir(E:\php\home);
print_r($result);
?>
40. Print out the time of yesterday’s moment, format: “year-month-day hour: minutes: seconds”
<?php
echo date(Y-M-D H:I:S, strtotime(-1 day, time());
?>
41. The meaning of several status codes in the HTTP protocol: 503,500,401,200,301,302
503 Request timeout
500 internal service errors, generally caused by the PHP program
401 Unauthorized access
200 correct response
301 Permanent redirect
302 Temporary redirect
42. Implement the function, convert the string “action_test” to actiontest, “my_book” to “mybook”
<?php
$a =ACTION_TEST;
$b = str_replace(_,,$a);
$c = ucwords($b);
$d = str_replace(,,$c);
echo $d;
?>
43. What are the magic methods in PHP5, please give an example to explain their usage?
__sleep serialization
__wakeup deserialization
__toString is called when printing an object
__invoke When trying to call an object as a function, it will be called automatically
__set_state
__construct construction method
__destruct destructor method
__call Automatically call when calling a method that does not exist in the class
__GET Automatically invoked when properties that are not present in the calling class or access level is limited
__Set is automatically called when the attributes that do not exist in the class or have limited access level are assigned
__isSet is automatically called when using the isSet function for attributes that do not exist in the class or the access level is limited
__unset is automatically called when the unset function is used for attributes that do not exist in the class or the access level is limited
__Clone is automatically called when cloning an object
When __autoload instantiates a class, if its corresponding class does not exist, it will be called automatically
44. What function can php use to reset the configuration in php.ini
ini_set()
45. Write the names of two or more MySQL storage engines, and briefly describe the difference?
MyISAM is the default storage engine of MySQL, supports full-text indexing, but is not transaction-safe, and does not support foreign keys
InnoDB does not support full-text indexing, it is transaction-safe
46. List some open source databases
MySQL Memcached MariaDB PostgreSQL
47. List some commonly used PHP extensions, such as GD
mysql mysqli pdo sockets zip openssl xmlrpc
48. Please convert “2014-2-17 00:00:00” to UNIX timestamp (the number of seconds in Greenwich Mean’s time to the current time), and format 1392612299 to the year, month, day format
<?php
echo strtotime(2014-2-17 00:00:00..<br />;
echo date(YMD, 1392612299);
?>
49. Please use php to find the number of days between 2014-2-17 to 2008-8-8?
<?php
$startDate = strtoTime(2014-2-17);
$enddate = mktime(0,0,0,8,8,2008);
echo round(($startdate-$enddate)/3600/24);
?>
50. Please put $aa=12,32,11,11Convert to array array(12,32,11,11) and restore it to $aa=12,32,11,11code;
<?php
$aa =12,32,11,11;
$aa_array = explore(,,12,32,11,11);
print_r($aa_array);
$BB = Implode(,,$aa_array);
echo $bb;
?>
51,
<?php
$b = 13;
6 + $a = $b;
echo(abs($a));
?>
13
52,
<?php
echo 1+2+”A+4+5″;
?>
3
53,
<?php
echo 1+2+”3+a+5″;
?>
6
54,
<?php
echo 1+2+”1+1+2″;
?>
4
55. Display the results:
<?php
$a = 12;
$b = 012;
$c = 0*12;
echo $a,”\n”,$b,”\n”,$c;
?>
12 10 0
56. When the output is Mozilla/5.0 (Windows NT 6.1; RV:32.0) Gecko/20100101 Firefox/32.0, the possible output statements are:
<?php
echo $_server[‘HTTP_USER_AGENT’];
?>
57. Which of the following statements is incorrect: D
A.PHP has four scalar types: Boolean, Integer (Integer), Float (Float), String (String)
b. Float and double are the same type
C. Compliance types include: array (array), object (object), resource (resource)
D. Pseudo-type: mixed (mixed), digital (number), callback (callback)
58. After executing the following code,
<?php
echo function_exists(printed);
?>
The output is: empty
59. The following functions that are not the components of PHP syntax are: a
A.Array it is a data structure not a regular function
The b.eval eval() function calculates the string according to the PHP code.
c.each returns the current key/value pair in the array and moves the array pointer one step forward
D.list list–Assign the values in the array to some variables
60. The following description of echo and print is correct: C
A.echo, print can print multiple parameters
b.print can print multiple parameters, echo cannot
c.echo can print multiple parameters, print cannot
D.echo, print can not print multiple parameters
61. The output of the following code is correct: C
<?php
$a = array(1=>5,5=>8,22,2=>881);
echo $a[7];
echo $a[6];
echo $a[3];
?>
A. Empty 2281
B. Empty 8122
C.8122 empty
d. empty empty
62. The output result of the following code: D
<?php
$a[bar]=hello;
echo $a[bar];
//Note: If there is no quotation mark, php can automatically convert the constant to a string, but the efficiency will be reduced, about 8 times
echo $a[‘bar’];
?>
a.hello
B. Empty
c. to report an error
d.hellohello
63. What is the result of executing the following code? a
<?php
$bool = true;
echo getType($bool);
echo is_string($bool);
?>
a.boolean
b.boolean0
c.booleanfalse
d.booleanfalse
Note: getType gets the variable type; is_string detects whether the variable is a string
64. Write the results of the following code: C
<?php
echo 1>>0;
echo 2>>1;
echo 3<<2;
//Note: Move one *2 to the left, remove 2 from the right
?>
A.012
B.106
C.1112
D.123
65. The execution result of the following code: a
<?php
for($i=0;$i<10;$i++){
//Note: the second parameter is less $, so it is not a variable is a constant, the constant is converted into a string and the number is converted into a number 0,0<10, so keep looping
print $i;
}
?>
A.0123456789
B.012345678910
c. No output
d. Infinite loop
66. For the front code
<?php
$fruits = array(Strawberry=>red,banana=>yellow);
?>
get the result correctlyyellowThe code is: ACD
<?php
echo “a banana is {$fruits[‘banana’]}”;
//Test site: embedded variables in double quotation marks, and the braces play the role of limiting the scope
//echo “a banana is $fruits[‘banana’]”;
echo “a banana is {$fruits[banana]}”;
//Type conversion, so slow, but correct
Echo “a banana is $fruits[banana]”;
// The variables in the double quotation marks stop until the special symbols are stopped, [it is not a special symbol, so it will continue to read downwards
?>
67, C
<?php
$foo =Test;
$bar = <<< eot
$foo bar
eot;
echo $bar;
?>
The above statement outputs the result:
a.$foo bar;
b.eot$foo bar eot;
c.test bar;
d.eottest bar eot
68, a
<?php
$a = 3;
$b = 4;
if($a||$b=5){
echotodo;
}
?>
The value of $b is ():
a.4;
$a=3;3 is a boolean true, so I won’t execute it back, so $b is still 4
B.5;
c.3;
d.false
69. What is the difference between preg_replace and preg_replace_callback?
preg_replace performs a regular expression search and replacement
preg_replace_callback performs a regular expression search and replaces with a callback
70. How to use CSS to display/hide a DOM element, if there are many, please point out their differences?
display:block;
display:none;
71. Please write a commonly used method to remove floating
Add an empty label after all floating elements inside the floating parent element that need to be cleared to clear the floating, .clear{clear:both;}
overflow:auto;zoom:1;
:after
72. What are the characteristics of the following styles if the divs use the following styles display:inline;display:block; display:inline-block;
display:inline; This element will be displayed as an inline element, there is no newline before and after the element
display:block; This element will be displayed as a block-level element with a newline before and after the element
display:inline-block; inline block elements
73. How does the bug of IE6 double margin appear and how can it be solved?
float, margin
display:inline;
74. Know a div style, width:100px;height:100px;margin:50px 20px;padding:50px 20px; what is the actual height of this div?
200px
75. How to make a container with a known width and height make it centered and topped in the page?
text-align:center;vertical:middle;
76. Determine whether the string is composed of this, the first one must be letters, followed by letters, numbers, and underscores, and the total length is 5-20 (using regular)
<script>
var reg = /^[a-zA-Z][a-zA-Z_0-9]{4,19}$/;
reg.test(“aeu3_di876”);
</script>
77. Please point out the phenomenon and solution of the compatibility problem of IE and FF scripts
(1) window.event;
Represents the current event object, ie has this object, ff does not, ff passes the event object to the event handler function
(2) Get the event source
IE uses srcelement to obtain the event source, and ff uses the target to obtain the event source
(3) Add and remove events
ie: element.attach(“onClick”, function); element.detach(“onClick”, function);
ff: element.addEventListener(“onClick”, function, true); element.removeEventListener(“onclick”, function, true);
(4) Get the custom attributes of the tag
IE: div.value, div[“value”]
FF: div.getAttribute[“value”]
(5) document.getElementByName() and document.all[name]
IE: can’t get elements
ff: yes
(6) Properties of Input.Type
IE: read only
FF: readable and written
(7) InnerText TextContent OuterHTML
IE: support InnerText OuterHTML
FF: Support TextContent
78. Inheritance implementation in object-oriented in JavaScript
<script>
function animation(name){
this.name = name;
}
animal.prototype.getname = function(){
alert(this.name)
}
function dog(){};
dog.prototype = new animal(“buddy”);
dog.prototype.constructor = dog;
var dog = new dog();
</script>
79. Write a method to remove the duplicate elements of an array
<script>
var arr =[1,1,2,3,3,2,1];
array.prototype.unique = function(){
var ret =[];
var o = {};
var len = this.length;
for (var i=0;i<len;i++){
var v = this[i];
if (!o[v]){
o[v]= 1;
ret.push(v);
}
}
return ret;
};
//alert(arr.unique());
</script>
80. How to detect a variable in JavaScript is a String type? Please write a function implementation
<script>
//There are two ways to generate the string type
//var str = “hello world”;
var str2 = new string(“Hello world”);
function isString(str){
return (typeof str == “string” || str.constructor == string);
}
var str = “”;
//alert(isString(1));
//alert(isString(str2));
</script>
81. Supplementary code, after clicking button1, move button1 to the back of button2
<div>
<input type=”button” id=”button1″ value=”1″ onclick=”moveBtn(this);” />
<input type=”button” id=”button2″ value=”2″ />
</div>
<script>
function moveBtn(obj) {
var clone = obj.cloneNode(true);
var parent = obj.parentNode;
parent.appendChild(clone);
parent.removeChild(obj);
}
</script>
82. How to spell the following CSS tags in JavaScript, border-left-color, -moz-viewport
BorderLeftColor
mozviewport
83. Please write a javascript function parseQueryString, its purpose is to parse the url parameter into an object
<script>
function parseQueryString(url){
var params = {};
var arr = url.split(“?”);
if (arr.length <= 1) return params;
arr = arr[1].split(“&”);
for(var i=0,l=arr.length; i<l; i++){
var a = arr[i].split(“=”);
params[a[0]] = a[1];
}
return params;
}
var url = “http://witmax.cn/index.php?key0=0&key1=1&key2=2”;
var ps = parseQueryString(url);
//alert(ps)[“key2”]);
</script>