Php interview questions with answers, php programmer pen questions and answers (1)

Source: Internet
Author: User
Select an appropriate function declaration for the user-defined function is_leap. Is_leap uses 2000 as the default year.

Php programmer recruitment questions:

Problem

1. select the appropriate answer and fill in the blank space

PHP is a ______ scripting language based on the ______ engine. PHP is most often used to develop dynamic ______

In addition, it can also be used to generate ______ (and others) documents.

A. dynamic, PHP, database, HTML

B. embedded, Zend, HTML, XML

C. Perl-based, PHP, Web, and static

D. embedded, Zend, Docbook, MySQL

E. Zend-based, PHP, image, HTML


2. Which of the following labels is not the PHP start/end character?

A. <%>

B .//

C.

D ./**/

E.


3. Which of the following code does not comply with the PHP syntax?

A. $ _ 10

B. $ {"MyVar "}

C. & $ something

D. $ 10_somethings

E. $ aVaR


4. what will be displayed when you run the following code?

Define (myvalue, "10 ");

$ Myarray [10] = "Dog ";

$ Myarray [] = "Human ";

$ Myarray ['myvalue'] = "Cat ";

$ Myarray ["Dog"] = "Cat ";

Print "The value is :";

Print $ myarray [myvalue]. "\ n ";

?>

2

A. The Value is: Dog

B. The Value is: Cat

C. The Value is: Human

D. The Value is: 10

E. Dog


5. what is the difference between print () and echo?

A. print () can be part of an expression, and echo () cannot

B. echo () can be part of an expression, and print () cannot

C. echo () can be used in PHP of CLI (command line) version, and print () cannot

D. print () can be used in PHP of CLI (command line) version. echo () cannot

E. no difference: both functions print text!


6. what is the output of the following script?

$ A = 10;

$ B = 20;

$ C = 4;

$ D = 8;

$ E = 1.0;

$ F = $ c + $ d * 2;

$ G = $ f % 20;

$ H = $ B-$ a + $ c + 2;

$ I = $ h <$ c;

$ J = $ I * $ e;

Print $ j;

?>

A.128

B .42

C.242.0

D.256

E.342


7. how to assign values to variables $ a, $ B, and $ c so that the following script displays the string "Hello, World !"?

$ String = "Hello, World! ";

$ A = ?;

3

$ B = ?;

$ C = ?;

If ($ ){

If ($ B &&! $ C ){

Echo "Goodbye Cruel World! ";

} Else if (! $ B &&! $ C ){

Echo "Nothing here ";

}

}

Else {

If (! $ B ){

If (! $ &&(! $ B & $ c )){

Echo "Hello, World! ";

} Else {

Echo "Goodbye World! ";

}

} Else {

Echo "Not quite .";

}

}

?>

A. False, True, False

B. True, True, False

C. False, True, True

D. False, False, True

E. True, True, True


8. what is output by the following script?

$ Array = '0123456789abcdefg ';

$ S = '';

For ($ I = 1; $ I <50; $ I ++ ){

$ S. = $ array [rand (0, strlen ($ array)-1)];

}

Echo $ s;

?>

A.50 random character string

B .49 character string composed of the same characters, because the random number generator is not initialized

C.49 string composed of random characters

D. nothing, because $ array is not an array

4

E.49 string consisting of letters 'g'


9. which statement structure is used to indicate the following conditions?

If ($ a = 'a '){

Somefunction ();

} Else if ($ a = 'B '){

Anotherfunction ();

} Else if ($ a = 'C '){

Dosomething ();

} Else {

Donothing ();

}

?>

A. There is no default switch statement

B. a recursive function

C. while statement

D. The logic cannot be expressed in other forms

E. There is a default switch statement


10. to modify the value of each element, how to traverse the $ myarray array is the most suitable?

$ Myarray = array ("My String", "Another String", "Hi, Mom! ");

?>

A. Use A for loop

B. use foreach loop

C. Use a while loop

D. use do... While loop

E. cannot do it!


11. Consider the following code snippet:

Define ("STOP_AT", 1024 );

$ Result = array ();

/* Enter the code here */

{

5

$ Result [] = $ idx;

}

Print_r ($ result );

?>

What code can be entered in the tag to generate the following array output?

Array

{

[0] => 1

[1] => 2

[2] => 4

[3] => 8

[4] => 16

[5] => 32

[6] => 64

[7] = & gt; 128

[8] = & gt; 256

[9] = & gt; 512

}

A. foreach ($ result as $ key => $ val)

B. while ($ idx * = 2)

C. for ($ idx = 1; $ idx <STOP_AT; $ idx * = 2)

D. for ($ idx * = 2; STOP_AT> = $ idx; $ idx = 0)

E. while ($ idx <STOP_AT) do $ idx * = 2


12. select an appropriate function declaration for the user-defined function is_leap. Is_leap uses 2000 as the default year.

/* Function declaration */

{

$ Is_leap = (! ($ Year % 4) & ($ year % 100) |

! ($ Year % 400 )));

Return $ is_leap;

}

Var_dump (is_leap (1987);/* Displays false */

Var_dump (is_leap ();/* Displays true */

?>

A. function is_leap ($ year = 2000)

B. is_leap ($ year defaults 2000)

C. function is_leap ($ year default 2000)

6

D. function is_leap ($ year)

E. function is_leap (2000 = $ year)


13. what values will be displayed when running the following code? Assume that the URL of the code is testscript. php? C = 25

Function process ($ c, $ d = 25)

{

Global $ e;

$ Retval = $ c + $ d-$ _ GET ['c']-$ e;

Return $ retval;

}

$ E = 10;

Echo process (5 );

?>

A.25

B .-5

C.10

D.5

E.0


14. Consider the following code:

Function myfunction ($ a, $ B = true)

{

If ($ &&! $ B ){

Echo "Hello, World! \ N ";

}

}

$ S = array (0 => "my ",

1 => "call ",

2 => '$ function ',

3 => '',

4 => "function ",

5 => '$ ',

6 => '$ B ',

7 => 'A ',

8 => 'B ',

9 => ");

$ A = true;

7

$ B = false;

/* Group */

$ Name = $ s [?]. $ S [?]. $ S [?]. $ S [?]. $ S [?]. $ S [?];

/* Group B */

$ Name ($ {$ s [?]}, $ {$ S [?]});

?>

Each question mark (?) in the script (?) Represents a numeric index of the $ s array. To display "Hello, World!" during code execution! Character

String, how do I select a digital index?

A. Group A:, Group B:

B. Group A:, Group B:

C. Group A:, Group B:

D. Group A:, 9, 9, 9 Group B:

E. Group A:, Group B:


15. run-time contains a PHP script using ______, while compile-time contains

Which of the following PHP scripts are used ______.

A. include_once, include

B. require, include

C. require_once, include

D. include, require

E. All of the above can be


16. under what circumstances cannot a default value be assigned to a parameter when a function is declared?

A. when the parameter is A Boolean value

B. When a function is a member of a class

C. when the parameter is passed through reference

D. when the function has only one parameter

E. never


17. ______ operator returns True if one (not all) of the two operands is True.

Answer :____________


18. equi operator === How do I compare two values?

A. convert them to the same data type and then compare the converted values.

B. True is returned only when both data types and values are the same.

8

C. If the two values are strings, the words are compared.

D. Comparison based on strcmp functions

E. convert both values into strings for comparison.


19. Which of the following options is to multiply the value of the integer variable $ a by 4? (Double choice)

A. $ a * = pow (2, 2 );

B. $ a >>= 2;

C. $ a <= 2;

D. $ a + = $ a + $;

E. none of them are correct.

20. how can I completely terminate a script?

A. When exit () is called

B. when the execution ends with the end of the file

C. When PHP crashes

D. When Apache is terminated due to system failure


The answer is displayed on the next page:

# P # php interview question answer # e #

Answer

1. the only meaningful answer is B. PHP is a script language based on the Zend Engine. it is usually embedded in HTML

Code. It is mainly used to develop HTML documents, but it can also be used to develop other types of documents.

For example, XML.

2. in PHP programming, people do not use <%> and two labels, but they are indeed legal PHP delimiters.

The tag is invalid, so the correct answer is D. Remember, depending on the configuration in the php. ini file

Some labels cannot be used under specific circumstances.

3. the PHP variable starts with a dollar sign, followed by any number of numbers, letters, and underscores. $ {"MyVar "}

Is a valid variable name, which uses a loose naming convention. & $ Something is for $ something

Reference. However, the variable name cannot start with a number and $ 10_somethings is invalid. Therefore, the answer is D.

4. Note that the key value of $ myarray is not enclosed in quotation marks. Therefore, the key being accessed is not a myvalue string,

It is the value of the constant myvalue. The final access is $ myarray [10]. The value is Dog and the answer is.

5. although print () and echo () can be used interchangeably in most cases, there is still a difference between them.

Print () is a function with returned values. echo () is actually a language structure with no returned values and cannot be stored in tables.

In dashboard. Therefore, the answer is.

6.% operator indicates the modulo operation. it returns the remainder of the division of two operands. < <是左移运算符,相当于乘以 2< p>

To the power of N. The final answer is multiplied by a floating point number, which changes its data type. However, since the decimal point

Therefore, the output result does not contain decimals. Answer: 256 (D ).

7. according to the conditional logic, to get Hello, World! String, which must satisfy the else in the first if structure

. Therefore, $ a must be False, and $ B must also be False. Implementation requirements of the innermost condition statement

The previous two variables ($ a and $ B) are False, while $ c must be True (the answer is D ).

8. the correct answer is C. Starting from PHP4.2.0, unless a pseudo-random integer column is specified

Use the srand () function to initialize the random number generator. In addition, even if the random number generator is not prefixed, the script

It still generates 49 pseudo-random characters. Although the $ array variable is a string, you can access the array

Row access-use a digital index to access characters at a certain position. Finally, the for loop starts from 1 to 50,

That is, 49 executions are performed.

9. use a series of if... The else statement is used to check the code block of a condition. it is best to use the switch statement instead.

Switch ($ ){

Case 'a ':

Somefunction ();

Break;

Case 'B ':

10

Anotherfunction ();

Break;

Case 'C ':

Dosomething ();

Break;

Default:

Donothing ();

}

?>

Because the if statement contains an else that captures all other conditions, the switch code block requires a default value.

The correct answer is E.

10. Generally, the foreach statement is the first choice for traversing arrays. However, since the foreach statement is in

And we need to assign a value to each element in the array, so foreach is not applicable here.

. Although we can also use the while loop and do... While loop, but because the array is ordered index, the most suitable

Statement or for statement. Therefore, the answer is.

$ Myarray = array ("My String", "Another String", "Hi, Mom! ");

For ($ I = 0; $ I <count ($ myarray); $ I ++)

{

$ Myarray [$ I]. = "($ I )";

}

?>

11. because only one line of code can be entered for a question, the only suitable one is the for loop, so the answer is only C or D.

To select a for loop that generates the correct results, we must first review the components of the for loop. PHP,

The for loop is declared as follows:

For ( <初始化> ; <继续执行,直到> ; <重复执行> )

<初始化> Execute once at the beginning of the loop, and then the for loop starts to execute the code in braces <继续< p>

Run until the value of> is False. Execute each time a loop is completed <重复执行> . Therefore, the correct generation

The code block should be:

For ($ idx = 1; $ idx <STOP_AT; $ idx * = 2)

The answer is C.

Of the 12.5 options, only two are valid PHP function declarations (A and D ). Among the two options, only one

The default value -- the answer is.

13. this question examines the scope of variables in PHP. You must specify how the global keyword introduces variables.

Global variables such as $ _ GET, $ _ POST, $ _ COOKIE, and $ _ REQUEST in the current region

Domain. In this question, the final mathematical expression is 5 + 25-25-10, equal to-5, and the answer is B.

14. the function can be dynamic in the form of parentheses (and necessary parameters) after a variable containing the function name.

Call. For Group A, the appropriate combination of indexes is 0, 4, 9, 9, 9, to generate the string myfunction.

On the other hand, the parameter will use variable variables in the $ {} structure. For Group B, the appropriate index should be 7

And 8, equal to $ {'a' }$ and {'B'} -- that is, $ a and $ B. So the answer is D.

15. in newer versions of PHP, require (or requier_once () and include () (or include_once () only have

One difference -- if the included file does not exist, the former will generate a fatal error and terminate the script execution.

And the latter generates only one warning. Therefore, answer E is correct.

16. when a parameter is declared as passed by reference, you cannot assign a default value to it. in this case, the interpreter expects to obtain

Variable modified within the function. The answer is C.

17. the correct answer is the logical xor (xor) operator.

18. full equal operator compares the data type and value of two operands. if there is a difference between the two, False is returned. Because

This answer is B.

19. The answer is A and C. In Option A, the pow function calculates the square of 2, and the answer is 4. In Option C, the left shift operation

To remove the value of $ a from the left, which is multiplied by 4.

20. The answer is. A script does not end when it is executed to the end of the file, so the current file can be used by other scripts

Include. As for the PHP and Apache crashes, these two statements are too bad.

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.