Php written test (II) 1. how can I use the php environment variable to get the content of a webpage address? How can I get the IP address?
Echo $ _ SERVER ['php _ SELF '];
Echo $ _ SERVER ['remote _ ADDR '];
?>
2. calculate the difference between two dates, for example, 2007-2-5 ~ Date difference of-3-6
$ Begin = strtotime ('2017-2-5 );
$ End = strtotime ('2017-3-6 );
Echo ($ end-$ begin)/24*60*60;
?>
3. write a function to implement the following functions:
Convert the string "open_door" to "OpenDoor" and "make_by_id" to "MakeById ".
Function changeStyle ($ str ){
$ ArrStr = explode ('_', $ str );
Foreach ($ arrStr as $ key => $ value ){
$ ArrStr [$ key] = strtoupper (substr ($ value, 0, 1). substr ($ value, 1 );
// $ ArrStr [$ key] = Ucfirst ($ arrStr [$ value]);
}
Return implode ('', $ arrStr );
}
$ Str1 = "open_door ";
$ Str2 = "make_by_id ";
Echo changeStyle ($ str1 );
Echo changeStyle ($ str2 );
4. write a program to convert the following array $ arr1 into an array $ arr2:
$ Arr1 = array (
'0' => array ('fid' => 1, 'tid' => 1, 'name' => 'name1 '),
'1' => array ('fid' => 1, 'tid' => 2, 'name' => 'name2 '),
'2' => array ('fid' => 1, 'tid' => 5, 'name' => 'name3 '),
'3' => array ('fid' => 1, 'tid' => 7, 'name' => 'name4 '),
'4' => array ('fid' => 3, 'tid' => 9, 'name' => 'name5 ')
);
$ Arr2 = array (
'0' => array (
'0' => array ('tid' => 1, 'name' => 'name1 '),
'1' => array ('tid' => 2, 'name' => 'name2 '),
'2' => array ('tid' => 5, 'name' => 'name3 '),
'3' => array ('tid' => 7, 'name' => 'name4 ')
),
'1' => array (
'0' => array ('tid' => 9, 'name' => 'name5') // content from technical world www.js4j.com technical enthusiast //
)
);
$ Arr1 = array (
'0' => array ('fid' => 1, 'tid' => 1, 'name' => 'name1 '),
'1' => array ('fid' => 1, 'tid' => 2, 'name' => 'name2 '),
'2' => array ('fid' => 1, 'tid' => 5, 'name' => 'name3 '),
'3' => array ('fid' => 1, 'tid' => 7, 'name' => 'name4 '),
'4' => array ('fid' => 3, 'tid' => 9, 'name' => 'name5 ')
);
Function changeArrayStyle ($ arr ){
Foreach ($ arr as $ key => $ value ){
$ Result [$ value ['fid'] [] = $ value;
}
Return array_values ($ result );
}
$ Arr2 = changeArrayStyle ($ arr1 );
Echo"
";
Var_dump ($ arr2 );
5. briefly describe the database design paradigm and application.
Generally, the 3rd paradigm is enough to optimize the table structure. This can avoid the complexity of applications and the low system efficiency caused by too large SQL statements.
ANSWER:
First paradigm: if every attribute of the relational model R cannot be decomposed, then it belongs to the first paradigm.
Second paradigm: if R belongs to the first paradigm, and all non-code attributes depend entirely on the code attributes, the second paradigm is used.
Third paradigm: if R belongs to the second paradigm, and none of all non-code attributes depend on candidate codes, then it belongs to the third paradigm.
6. the Id in a table has multiple records. check all records of this id and display the total number of records. these records are implemented using SQL statements, views, and stored procedures.
Stored Procedure: // content from technical world www.js4j.com professional technology //
DELIMITER //
Create procedure proc_countNum (in columnId int, out rowsNo int)
Begin
Select count (*) into rowsNo from member where member_id = columnId;
End
Call proc_countNum (1, @ no );
Select @ no;
View:
Create view v_countNum as select member_id, count (*) as countNum from member group by member_id
Select countNum from v_countNum where member_id = 1
7. The table contains three columns A, B, and C, which are implemented using SQL statements: Select Column A if Column A is greater than Column B; otherwise, select column B, if Column B is greater than column C, column B is selected; otherwise, column C is selected.
Select
Case
When first_name> middle_name then
Case when first_name> last_name then first_name
Else last_name end
Else
Case when middle_name> last_name then middle_name else last_name
End
End as name
From member
8. briefly describe how to optimize the SQL statement execution efficiency in the project. In what ways can we analyze the SQL statement performance?
ANSWER: SQL optimization is useful, so it is better to add indexes directly.
9. if the template is a smarty template. How to use the section Statement to display an array named $ data. For example:
$ Data = array (
[0] => array ([id] = 8 [name] = 'name1 ′)
[1] => array ([id] = 10 [name] = 'name2 ′)
[2] => array ([id] = 15 [name] = 'name3 ′)
......
)
Write the code on the template page? How can I display it with the foreach statement?
Accounts for no answer.
10. write a function to traverse all files and subfolders in a folder. (Directory Operations)
$ D = dir (dirname (_ file __));
// Echo "Handle:". $ d-> handle. "\ n ";
// Echo "Path:". $ d-> path. "\ n ";
While (false! ==( $ Entry = $ d-> read ())){
Echo $ entry ."
";
}
$ D-> close ();
11. two city and province tables. These are the relationship tables between cities and provinces.
City:
Id City Provinceid
1 Guangzhou 1
2 Shenzhen 1
3 Huizhou 1
4 Changsha 2
5 Wuhan 3
.......... Guangzhou // This article is from technical world www.js4j.com technical tutorial //
Province:
Id Province
1 Guangdong
2 Hunan
3 Hubei
..........
(1) Write an SQL statement to link two tables. implementation: display the basic information of the city .?
(2) display field: City id, city name, and province.
For example:
Id (City id) Cityname (city name) Privence (province)
.........
.........
(2) If you want to count the number of cities in each province, use group by to query them .?
Display field: province id, province name, and number of cities.
ANSWER:
1. select A. id, A. Cityname, B. Province from city A, province B where A. provinceid = B. id
2. select B. id, B. Province, count (*) as num from city A, province B where A. provinceid = B. id group by B. id
12. based on your experience, briefly describe the steps for software development in software engineering. What are the disadvantages of the following tools used by Rational Rose, PowerDesigner, Project, VSS, CVS, and TestDirector?
The company uses dbdesigner and cvs, and the test management tool uses Mantis.
13. briefly describe the differences between the operating system threads and processes. List the software you have used in LINUX?
14. Use a pseudo-language combined with the data structure bubble sorting method to sort the following groups of data 10 2 36 14 10 25 23 85 99 45. // This article is from the technical world www.js4j.com technical tutorial //
Function bubble_sort (& $ arr ){
$ Number = count ($ arr );
For ($ I = 0; $ I <$ number-1; $ I ++ ){
For ($ j = 0; $ j <$ number-1-$ I; $ j ++ ){
If ($ arr [$ j]> $ arr [$ j + 1]) {
$ Tmp = $ arr [$ j];
$ Arr [$ j] = $ arr [$ j + 1];
$ Arr [$ j + 1] = $ tmp;
}
}
}
}
$ Str = "10 2 36 14 10 25 23 85 99 45 ";
$ Arr = explode ("", $ str );
Bubble_sort ($ arr );
Echo"
";
var_dump($arr);