Reprinted-php questions

Source: Internet
Author: User
Reprinted-php question 1. write the results of the following code:
$ A = "Hello World! ";
$ B = $;
Print ("\ $ B = $ B
");
Print ('$ a = $
');
?>

$ B = Hello World!
$ A = $
// '\' Is an escape character, blocking the special usage of a single special character that follows
// ''Single quotes, shielding the special meanings of almost all special characters including
// In addition, debug the code in the command line,
It is not output as a line feed ~ If it is in browser, let alone

2. write the following code to output the result:
$ A = "First ";
$ B = & $;
$ C = $;
$ A = "Second ";
Print ("$ a, $ B, $ c
");
?>

Second, Second, First
// $ B is the value assigned by $ a, so the change of $ a is the change of $ B.
// $ C can be seen as a copy after $ a is copied once, so it is irrelevant two variables. Therefore, the change of $ a does not affect $ c.

3. write the following code to output the result:
$ A = 2;
$ B = "1.2SBC3 ";
$ C = "EFG ";
$ Result1 = $ a. $ B;
$ Result2 = $ a * $ B;
$ Result3 = $ a * $ c;
Print ("$ result1, $ result2, $ result3
");
?>

21.2sbc3, 2.4, 0
// $ Result1 is the string connection, btw. if the question is 2. $ B, the system reports an error.
// $ Result2 is the multiplication of numbers. in php, the first character that is not a number is automatically discarded.
// $ Result3 is the multiplication of numbers. different from 2, $ c does not have any numeric characters, so the whole is forcibly converted to numeric, that is, 0, then multiply with $ a = 2 and the final result is 0.

4. the following incorrect variable names are:
A. $ _ test B. $ 2abc C. $ Var D. $ % Var

B

5. statement for ($ k = 0; $ k = 1; $ k ++); and Statement for ($ k = 0; $ k = 1; $ k ++ ); the execution times are:
A. infinite and 0 B. 0 and infinite C. Both are infinite D. Both are 0

A

/**
* Here we will focus on this question. it should be okay to select A here, which is well known.
* The problem is, if the first sentence is changed to for ($ k = 0; $ k = 0; $ k ++), how many times will the loop be executed?
*
* The answer is 0.
*
* The reason is that for (expr A; expr B; expr C) is concerned with the true value of the expression expr B when determining whether to execute the loop body.
* Note! $ K = 0 the value of this expression is 0! Instead of the possible one returned after successful replication!
* Therefore, if the cycle judgment condition of the for loop is always false, the loop body will not be executed ~~~
*
*:)
**/


6. php functions do not support the following functions:
A. variable function name B. variable number of parameters C. passing parameters through reference
D. pass the parameter E through the pointer to implement recursive functions

D

7. Which of the following statements about php classes is false:
A. support single inheritance B. support multiple inheritance C. constructor D. Not Support destructor
E. The $ this pointer must be used to reference member variables.

B multi-inheritance seems to require interfaces

8. locate and correct the errors in the following code:
$ A [0] = "" Ryan;
$ B ["value"] = 785.9;
$ C ["blue"] [0] = "Ada ";
Print ("$ a [0], $ B [" value "], $ c [" blue "] [0]
");
?>

$ A [0] = "Ryan ";
$ B ["value"] = 785.9;
$ C ["blue"] [0] = "Ada ";
Print ("$ a [0]". "$ B [value]". "{$ c [blue] [0]}"."
");
?>

// There is nothing to say about quotation marks
// The key is the $ c [blue] [0] of the last line. if you do not enclose it in curly brackets, the system automatically replaces $ c [blue] with the variable. the problem is that this value does not exist. Therefore, the xxxx [0] after the replacement is complete will no longer exist, so an error will be reported. This is the so-called variable array.


9. write the priority of the following operators in the order from high to low:
And, =,>, + ,~

~ +> = And I guess

10. differences between isset () and empty ()


Isset ()
Test whether the variable exists

Empty ()
Test whether the variable is null

In a language like php that does not strictly define variables
If a variable has never been declared, isset = false | empty = true
If a variable has been declared, but the value is NULL, it is the same as the previous case.
If a variable has been declared but assigned a value of '', isset = true | empty = true
If a variable has been declared and assigned a value normally, isset = true | empty = false

Example as follow:
$ B = NULL;
$ C = '';
$ D = 'str ';
Echo isset ($ a). "a \ n ";
Echo empty ($ a). "B \ n ";
Echo isset ($ B). "c \ n ";
Echo empty ($ B). "d \ n ";
Echo isset ($ c). "e \ n ";
Echo empty ($ c). "f \ n ";
Echo isset ($ d). "g \ n ";
Echo empty ($ d). "h \ n ";
?>

11. use as few statements as possible to verify the input Email address.

Eregi ('^ [_ a-z0-9] + (\. [_ a-z0-9-] +) * @ [a-z0-9] + (\. [a-z0-9-] +) * $ ', $ emailaddress)

12. write an algorithm, sort the following arrays in ascending order, and write the name of the sorting algorithm:
$ ArrVar = array)

Bubble sorting, process omitted

13. write a program that converts the first letter of each word in a text file into a large one and saves it back to the original file.
Tip: convert the first letter of a word in a string to a function of uppercase: string ucwords (string str)



14. write out several methods for accessing the MYSQL database using php and give a brief introduction.

15. write out the PHPSession implementation method. introduce the implementation method that you think is the best, and explain the reasons.
Tip: SessionID transmission method, Session variable storage method, etc.

16. What are the vulnerabilities in PHP?

I am the biggest vulnerability ......


I don't know, right ~~ Haha ~~ I found that conceptual things are quite ambiguous ~~
Write more words slowly ~~~ :)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.