20100318-PHP面试考试题总结

2010年3月18日面试考试题目及个人总结 /*************by garcon1986*********************/ 1. Array_shift 删除数组的第一个元素 array_shift — Shift an element off the beginning of array <?php $stack = array ( "orange" , "banana" , "apple" , "raspberry" ); $fruit = array_shift( $stack ); print_r( $stack ); ?> 结果 : Array ( [0] => banana [1] => apple [2] => raspberry ) 2. pcntl_exec(), exec()区别 exec — Execute an external program <?php // outputs the username that owns the running php/httpd process // (on a system with the "whoami" executable in the path) echo exec( 'whoami' ); ?> 结果 : garcon1986-pc/garcon1986 函数对比: pcntl_exec — Executes specified program in current process space system — Execute an external program and display the output passthru — Execute an external program and display raw output 3. If the input of chr() is $a and the output is $b, what function would take input $b and produce output $a? chr — Return a specific character chr()函数的作用是:返回指定 ASCII值所对应的字符。 <?php echo chr( 52 ). "<br />" ; echo chr( 052 ). "<br />" ; echo chr( 0x52 ). "<br />" ; ?> 结果 : 4 * R 相反功能的函数ord(): Ord() - Return ASCII value of character 返回字符对应的 ASCII 码 <?php $str = "/n" ; echo ord( $str ). '<br />' ; $str2 = " " ; echo ord( $str2 ); ?> 结果: 10 32 printf — Output a formatted string 输出一个格式化的字符串 <?php printf( 'http://www.%1$s.%2$s' , 'dayanmei' , 'com' ); ?> 结果: http://www.dayanmei.com sprintf — Return a formatted string 返回一个格式化的字符串(不输出) <?php $s = sprintf( 'http://%3$s.%1$s.%2$s' , 'dayanmei' , 'com' , 'www' ); echo $s ; ?> 结果: http://www.dayanmei.com 4. magic quotes Which function returns true when magic quotes are turned on? Warning: This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged. 5. If $arr was an array of ten string elements with specific keys, what would array_values(ksort($arr)) do? Choose only one of the following Create a new array of just the values, then sort by the keys Create a new array of just the values, then ignore the sort as there are no keys Sort the array by key, then return a new array with just the values Trigger a warning None of the above No answer 答案: Trigger a warning ksort() 函数按照键名对数组排序,为数组值保留原来的键。 <?php $my_array = array ( "c" => "Dog" , "b" => "Cat" , "a" => "Horse" ); ksort($my_array ); print_r( $my_array ); ?> 结果 : Array ( [a] => Horse [b] => Cat [c] => Dog ) <?php $arr = array ( "b" => "world" , "a" => "hello" , "c" => "!" ); ksort( $arr ); print_r(array_values( $arr )); ?> 结果: Array ( [0] => hello [1] => world [2] => ! ) <?php $arr = array ( "b" => "world" , "a" => "hello" , "c" => "!" ); print_r(array_values(ksort( $arr ))); ?> 结果: Warning : array_values() [function.array-values ]: The argument should be an array in C:/wamp/www/eclipse/ubb/test2.php on line 3 6. Output buffering compression is... Choose only one of the following High on CPU resources, low on network resources Low on CPU resources, high on network resources High on CPU resources, high on network resources Low on CPU resources, low on network resources No answer 答案:目前不清楚 7. Examine this code - on which line is there an error? <?php class dog { public function bark() { echo "Woof!"; } }; $foo = new dog; $foo->bark(); ?> Choose only one of the following Line 2 (class dog) Line 3 (public function bark()) Line 4 (echo "Woof!") Line 6 ( }; ) Line 8 ($foo = new dog) Line 9 ($foo->;bark()) There is no error No answer 答案: There is no error 结果:Woof! 8. What directive would you change in your php.ini file to disable assert()? Choose only one of the following assert assert.active assert.enable assert.assert assert.options None of the above No answer 答案:assert.active php.ini中assertion部分代码: [Assertion] ; Assert(expr); active by default. ; http://php.net/assert.active ;assert.active = On ; Issue a PHP warning for each failed assertion. ; http://php.net/assert.warning ;assert.warning = On ; Don't bail out by default. ; http://php.net/assert.bail ;assert.bail = Off ; User-function to be called if an assertion fails. ; http://php.net/assert.callback ;assert.callback = 0 ; Eval the expression with current error_reporting(). Set to true if you want ; error_reporting(0) around the eval(). ; http://php.net/assert.quiet-eval ;assert.quiet_eval = 0 9. "10" == 10: true or false? Choose only one of the following True False 答案: True <?php if ( "10" == 10 ){ echo "true" ; } else { echo "false" ; } ?> 结果 : true 10. 010 >= 10: true or false? Choose only one of the following True False No answer 答案: False <?php if ( 010 < 10 ){ echo "true" ; } else { echo "false" ; } ?> 结果 : true 11. This SQL statement is valid "SELECT ID, Name FROM some_table ORDER BY Name WHERE ID < 100" - true or false? Choose only one of the following True False No answer 答案: False 例子 1: SELECT * FROM entreprise WHERE name LIKE 'enterprise%' ORDER BY id 结果显示正常。 Showing rows 0 - 1 (2 total, Query took 0.0004 sec) 例子 2: SELECT * FROM entreprise ORDER BY id WHERE name LIKE 'enterprise%' 错误:#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE name LIKE 'enterprise%' LIMIT 0, 30' at line 4 12. SQLite is compiled into PHP 5 by default: true or false? Choose only one of the following True False No answer 答案:False(目前不太确定) 13. What is the best description of a normalized table? Choose only one of the following One where optimal data types are used One where data is not repeated One where the schema is valid One that is properly indexed One that has been defragmented No answer 答案: One where optimal data types are used 14. What is the case-insensitive version of the strcmp() function? Choose only one of the following strcmpi() stricmp() strcasecmp() istrcmp() No answer 答案: strcasecmp() <?php //strcasecmp 注释:该函数是二进制安全的,且对大小写不敏感。比较两个字符串。 // 该函数返回: // * 0 - 如果两个字符串相等 // * <0 - 如果 string1 小于 string2 // * >0 - 如果 string1 大于 string2 echo strcasecmp( "Hello world!" , "HELLO WORLD!" ). "<br />" ; // 结果 0 echo strcasecmp( "he" , "hf" ); // 结果 -1 echo strcasecmp( "he" , "hd" ); // 结果 1 ?> 15. The parse_str() function... Choose only one of the following Checks a string of PHP code is valid Checks a string of PHP code is valid, then executes it Searches a string for non-English characters Converts the contents of a string into variables No answer 答案:Converts the contents of a string into variables 16. What would implode(".", explode(",", $string)) do? Choose only one of the following Replace all full stops (periods) with spaces Replace all full stops with commas Delete all full stops None of the above No answer 答案: No answer 应该是把所有逗号 comma(,)替换为点号 stop(.) <?php $str = "Hello,world,It's,a,beautiful,day" ; //print_r (explode(",",$str)); echo implode( "." , explode( "," , $str )); ?> 结果:Hello.world.It's.a.beautiful.day

你可能感兴趣的:(面试,String,NetWork,resources,output,2010)