Juju technology-php development pen questions and answers, php Questions and answers
Juju technology is a newly founded company with very small and few people. The boss feels like a typical Beijing hacker. It is very arrogant and has a personality. The exam is simple:
1. What are the differences between echo (), print (), and print_r?
Echo is the PHP language structure, and print and print_r are functions. The language structure does not return values. functions can return values (even if not ).
Print () can only print values of simple type variables (such as int and string)
Print_r () can print values of complex types of variables (such as arrays and objects)
Echo outputs one or more strings
2. What is the difference between include and require statements? To avoid multiple accesses to the same file (?) Statement substitution?
Require generates a fatal error (E_COMPILE_ERROR). The execution will be stopped when an error occurs.
Include generates a warning (E_WARNING), which will continue when an error occurs.
Replace require_once () and include_once.
3. What is the difference between passing a value in php and passing a reference? When will the value be passed, and when will the reference be passed?
Pass by value: any changes to the value within the function range will be ignored outside the function;
Pass by reference: any changes to values within the function range can also reflect these changes outside the function.
Advantages and disadvantages: When passing by value, php must copy the value. This is especially costly for large strings and objects.
Transferring by reference does not require copying values, which is good for performance improvement.
4. the SQL query statement is as follows: select * from table where (ID = 10) or (ID = 32) or (ID = 22) or (ID = 76) or (ID = 13) or (ID = 44), let the results be retrieved in the order of 10, 32, 44. Could you please write?
select *from table where id in(10,32,22,76,13,44)order by instr(',10,32,22,76,13,44,', ','+id+',')
5. How does one detect a variable of the string type in Javascript? Please write out the function to implement the String type in two ways.
The String type can be generated in two ways:
(1) Var str = "hello world ";
(2) Var str2 = new String ("hello world ");
1 function IsString(str){2 return (typeof str == "string" || str.constructor == String);3 }4 var str = "";5 alert(IsString(1));6 alert(IsString(str));7 alert(IsString(new String(str)));
6. What is the difference between document. write and innerHTML?
Document. write is the content stream directly written to the page. If document. open is not called before writing, the browser automatically calls open. The page will be overwritten when the function is called again after it is closed. InnerHTML is an attribute of a DOM page element, representing the html content of the element. You can change a specific element accurately. If you want to modify the content of a file, modify document.doc umentElement. innerElement. InnerHTML writes content to a DOM node, which does not cause the page to repaint all innerHTML, which is superior to document in many cases. write, the reason is that it allows more precise control of the part of the page to be refreshed.
7. Write a sorting algorithm, which can be Bubble sorting or fast sorting. Assume that the object to be sorted is a one-dimensional array.
1 <? Php 2/** 3 * sorting class 4 */5 class Sort {6/* 7 * Bubble Sorting small to 8 */9 public function bubble_sort ($ array) {10 $ count = count ($ array); 11 if ($ count <= 0) 12 return false; 13 for ($ I = 0; $ I <$ count; $ I ++) {14 for ($ j = 1; $ j <= $ count-$ I-1; $ j ++) {15 if ($ array [$ j] <$ array [$ j-1]) {16 $ tmp = $ array [$ j]; 17 $ array [$ j] = $ array [$ j-1]; 18 $ array [$ j-1] = $ tmp; 19} 20} 21} 22 return $ array; 23} 24 25 26/** 27 * fast sorting 28 */29 public function quick_sort ($ arr) {30 $ len = count ($ arr ); 31 if ($ len <= 1) 32 return $ arr; 33 $ key = $ arr [0]; 34 $ left_arr = $ right_arr = array (); 35 for ($ I = 1; $ I <$ len; $ I ++) {36 if ($ arr [$ I] <= $ key) 37 $ left_arr [] = $ arr [$ I]; 38 else39 $ right_arr [] = $ arr [$ I]; 40} 41 $ left_arr = $ this-> quick_sort ($ left_arr); 42 $ right_arr = $ this-> quick_sort ($ right_arr); 43 Return array_merge ($ left_arr, array ($ key), $ right_arr); 44} 45 46 47/** 48 * Hill sorting 49 */50 public function shell_sort ($ datas) {51 // group 52 for ($ increment = count ($ datas)/2; $ increment> 0; $ increment = $ increment/2) {53 // sort each group by 54 for ($ I = $ increment; $ I <count ($ datas); $ I ++) {55 $ temp = $ datas [$ I]; 56 $ j = 0; 57 for ($ j = $ I; $ j >=$ increment; $ j = $ j-$ increment) {58 if ($ te Mp <$ datas [$ j-$ increment]) {59 $ datas [$ j] = $ datas [$ j-$ increment]; 60} else {61 break; 62} 63} 64 $ datas [$ j] = $ temp; 65} 66} 67 return $ datas; 68} 69} 70?>
If any of the above content is incorrect, please advise. Thank you!