Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Which 10 questions are worth pondering in the PHP interview questions?

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

In this issue, the editor will bring you about which 10 questions in the PHP interview questions are worth pondering. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Q1

The first question is about weak types.

$str1 = 'yabadabadoo';$str2 =' yaba';if (strpos ($str1,$str2)) {echo "/". $str1. "/" contains / ". $str2." / ";} else {echo" / ". $str1." / "does not contain /". $str2. "/";}

The output of the correct operation:

"yabadabadoo" does not contain "yaba"

Strpos returns the position of the string str2 in str1, and returns false if it is not found. In fact, 0 is returned this time and 0 is also regarded as false in the if statement, so we need to determine the type of false. The correct code is as follows:

$str1 = 'yabadabadoo';$str2 =' yaba';if (strpos ($str1,$str2)! = = false) {echo "/". $str1. "/" contains / ". $str2." / ";} else {echo" / ". $str1." / "does not contain /". $str2. "/";}

It's important to note that we used! =, in php and JS =! Relative = is more stringent and requires consistent data types.

Q2

What will the following output look like?

$x = 5echo x; echo ""; echo $xecho; echo ""; echo ""; echo $x; echo ""; echo $xmuri; echo "; echo $x

The actual operation result is

five

eleven

seven

one

five

The problem of $xbirthday + and $x-is actually very easy to encounter, we just need to remember that $xbirthday + uses the most recent value and then increments itself.

The priority of the operator, + + is significantly higher than +, so execute + before +. With regard to the priority of operators, sometimes we can really use parentheses to make our program more intuitive, after all, code is not only for execution, sometimes maybe the readability of the team is also a way to improve efficiency.

Q3

About the reference of variables

$a = '1candidate / b = & $a / s / b = "2$ b"

What are the values of $an and $b, please?

Part of the first time you will think of $a hundred and twenty-one, take a closer look at $baked examples, where $b is a reference to the variable $a rather than a direct assignment.

Q4

Is it true or false?

Var_dump (0123 = = 123s); var_dump ('0123' = = 123s); var_dump (' 0123' = 123s); var_dump (0123 = = 123s); / / false,PHP will treat 0123 as octal by default, and the actual conversion to decimal is 83, which is obviously not equal. Var_dump ('0123' = = 123); / / true here php will be very interesting to convert '0123' to a number and by default remove the previous 0, that is, 123==123var_dump ('0123' = 123); / / false obviously mentioned the inconsistency between the number and the string type.

Q5

Is there something wrong with the following code? What will the output be and how to fix it?

$referenceTable = array (); $referenceTable ['val1'] = array (1,2); $referenceTable [' val2'] = 3politics referenceTable ['val3'] = array (4,5); $testArray = array (); $testArray = array_merge ($testArray, $referenceTable [' val1']); var_dump ($testArray); $testArray = array_merge ($testArray, $referenceTable ['val2']); var_dump ($testArray); $testArray = array_merge ($testArray, $referenceTable [' val3']); var_dump ($testArray)

The actual output is as follows:

Array (2) {[0] = > int (1) [1] = > int (2)} NULLNULL

While running, you may also see the following warning

Warning: array_merge (): Argument # 2 is not an array

Warning: array_merge (): Argument # 1 is not an array

Array_merge requires that all the parameters passed in are arrays. If not, null is returned. You can modify it like this.

$testArray = array_merge ($testArray, (array) $referenceTable ['val1']); var_dump ($testArray); $testArray = array_merge ($testArray, (array) $referenceTable [' val2']); var_dump ($testArray); $testArray = array_merge ($testArray, (array) $referenceTable ['val3']); var_dump ($testArray)

Q6

What should $x be output?

$x = true and false;var_dump ($x)

Some students may think of false for the first time, but in fact, the priority of the operator is still emphasized here, and = will be higher than the and level, so it is equivalent to the following code

$x = true;true and false

The answer is obvious.

Q7

What should be the value of $x after the following calculation?

$x = 3 + "15%" + "$25"

The answer is that 18PhonePHP will automatically convert types according to the context.

The above code can be understood like this. If we are doing mathematical operations with a string, the actual php will convert the array in the string as much as possible, and convert it into a changed number if it starts with a number. For example, "15%" will become 15, and if it is not the beginning of a number, it will become 0. The above operation is similar to the following:

$x = 3 + 15 + 0

Q8

Run the following code, what is the value of $text, and what result will strlen ($text) return?

$text = 'John'; $text [10] = 'Doe'

After the above code is executed, $text = "John D" (John will be followed by 5 consecutive spaces) strlen ($text) will return 11

When $text [10] = "Doe" is assigned to a specific character at a specific position in a string, D is actually only assigned to $text. Although $text only starts with five conceited lengths, php fills in blanks by default. This is a little different from other languages.

Q9

What will be the following output?

If ($l > $m > $v) {echo "yes";} else {echo "no";}

The actual output is "no". It is not difficult to find out if you analyze it carefully.

$l > $m will be converted to 1, and then compare with $m at this time.

Q10

What will be the value of $x by executing the following code?

$x = NULL; if ('0xFF' = = 255) {$x = (int)' 0xFFF;}

The actual running result is $xroom0 instead of 255. 0.

First of all, 'oxFF' = = 255. we can judge that the conversion will be carried out to convert hexadecimal numbers to decimal digits, 0xff-> 255.

PHP uses is_numeric_string to determine whether the string contains hexadecimal digits and then converts it.

But will $x = (int) '0xFFF; also become 255? Obviously not, convert_to_long is actually used to cast a string, which actually converts the string from left to right and stops when it encounters a non-numeric character. So 0xFF stops at x. So $xylene 0

The above is the editor for you to share the PHP interview questions which 10 questions are worth pondering, if there happen to be similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report