1. 程式人生 > >Yahoo! PHP 筆試題

Yahoo! PHP 筆試題

1. Which of the following will not add john to the users array?

1. $users[] = ‘john’;
2. array_add($users,’john’);
3. array_push($users,’john’);
4. $users ||= ‘john’;

2.沒有array_add這個函式;
4.語法錯誤。

2. What’s the difference between sort(), asort() and ksort? Under what circumstances would you use each of these?

看手冊的:

sort:本函式對陣列進行排序。當本函式結束時陣列單元將被從最低到最高重新安排。注: 本函式為 array 中的單元賦予新的鍵名。這將刪除原有的鍵名而不僅是重新排序。

asort:對陣列進行排序並保持索引關係

ksort:對陣列按照鍵名排序,保留鍵名到資料的關聯。

3. What would the following code print to the browser? Why?

$num = 10;
function multiply(){
$num = $num * 10;
}
multiply();
echo $num;

10,一個是全域性變數,一個是區域性變數。而且PHP中的全域性變數跟C中的不一樣,在函式中使用要申請為全域性變數才行。

4. What is the difference between a reference and a regular variable? How do you pass by reference & why would you want to?

5. What functions can you use to add library code to the currently running script?

6. What is the difference between foo() & @foo()?

7. How do you debug a PHP application?

8. What does === do? What’s an example of something that will give true for ‘==’, but not ‘===’?

9. How would you declare a class named “myclass” with no methods or properties?

10. How would you create an object, which is an instance of “myclass”?

11. How do you access and set properties of a class from within the class?

12. What is the difference between include & include_once? include & require?

13. What function would you use to redirect the browser to a new page?
1. redir()
2. header()
3. location()
4. redirect()

14. What function can you use to open a file for reading and writing?

1. fget();
2. file_open();
3. fopen();
4. open_file();

15. What’s the difference between mysql_fetch_row() and mysql_fetch_array()?

16. What does the following code do? Explain what’s going on there.
$date=’08/26/2003′;
print ereg_replace("([0-9]+)/([0-9]+)/([0-9]+)",2/1/3,$date);

17. Given a line of text $string, how would you write a regular expression to strip all the HTML tags from it?

18. What’s the difference between the way PHP and Perl distinguish between arrays and hashes?

19. How can you get round the stateless nature of HTTP using PHP?

20. What does the GD library do?

21. Name a few ways to output (print) a block of HTML code in PHP?

22. Is PHP better than Perl? – Discuss.