Home  >  Article  >  Backend Development  >  PHP basic question and answer knowledge summary sharing

PHP basic question and answer knowledge summary sharing

小云云
小云云Original
2018-02-28 09:05:156148browse

This article mainly shares with you a summary of basic PHP Q&A knowledge, hoping to help everyone.

01. When the output is Mozilla/4.0 (compatible; MSIE5.01; WindowNT5.0), the possible output statements are:

A. $_SERVER['HTTP_USER_AGENT_TYPE'];

B.$_SERVER['HTTP_USER_AGENT'];

C.$_SERVER['USER_AGENT'];

D.$_SERVER['AGENT'];

02. The following functions cannot be achieved by PHP:

A. Server-side script running

B. Command line script running

C. Client graphical interface (GUI) program

D. Browser execution of DOM operations

03. The following statement is incorrect:

A.PHP has four scalar types: boolean, integer, float, and character String(string)

B. Float and double are the same type

C. Composite types include: array ), object, resource

## D. Pseudo-type: mixed, number, callback

04. After executing the following code,

Echo function_exists('print');

?>

1. Function_exists determines whether the function exists and returns true or false

2. Print itself is not a function, but a Language structure

3. Echofalse Nothing

The output obtained is:

A.empty

B.true

C.false

D.FALSE

05. Below Functions that are not part of the PHP syntax are:

A.array

B.eval

C.each

D.list

Echoprint

06. What is the result of executing the following code?

$bool=TRUE;

Echo gettype($bool);

Echo is_string($bool);

?>

A.boolean

B.boolean0

C.booleanFALSE

D.booleanfalse

*07. Write the result of executing the following code:

$a=12;

$b =012;

            $c=0x12;  

                               --                                                                                          

##12\n10\n18

08. What is the execution result of the following code?

Echo 1+2+"3+4+5";

?>

A.0

B.3

C.6

D."33+4+5";

09 .The following code returns TRUE after adding the following function:

Return ?=='A';

A.ord(65) According to the character, returns the ascii code value

B.chr(65)According to the ascii code value, return the corresponding character A==65 a==97

C.65+''

D.''+65

10. The correct output of the following code is:

$a= array(1=>5,5=>8,22,2=>'8',81);

Echo $a[7];//81

Echo $a[6];//22

Echo $a[3];

?>

A. Empty 2281 B. Empty 8122 C. 8122 Empty D. Empty Empty Empty

11. The output of the following code:

$a[bar] ='hello';

Echo $a[bar];//hello

echo $a['bar'];//hello

?>

A.hello B. Empty C. Error D.hellohello

*12. Write the result of the following code:

Echo 1>>0; 0001

Echo 2>>1; 0010 -> 0001

Echo 3<<2; 0011 -> 1100

?>

A.012 B.106 C.1112D.123

13 .The following description of echo and print is correct:

A. Both echo and print can print multiple parameters

B. Print can print multiple parameters, but echo cannot

C.echocan print multiple parameters,printcannot

D. Echo and print cannot print multiple parameters

14. For the following code

$fruits= array('strawberry'=>'red','banana'=>'yellow');

?>

The code that can correctly get the result 'yellow' is:

A.echo"A banana is {$fruits['banana']}";

B.echo"A banana is $fruits['banana']" ;

C.echo"A banana is {$fruits[banana]}";

D.echo"A banana is $fruits[banana]";

15. What is the result after the following code is executed?

Function change(){

Static$i=0;

$i++;

Return$ i;

}

                                                                                            using         using       through ’’s way through ’ through ’ s   through ’’s ’     through       through through ‐ through ‐ through ‐ through through through through through through through‐‐ to to the right to print to. 12

##16. After the following code is executed, the $result value is:

$ srcArray = array('a','b','c','d'); ;

?>

1.

array_rand

What does it return?

2.

Is_string()Return value A , a

B,false ​ C. trueb

​ D. b

E. c

17.What is the output? A. 3 B. false

C. null

D

1

E. 0

18. After the execution of the following code, the $result value is:

$a = '01 '; ## $ result = 1; If (in_array ($ a, array (' 1 '))) { ## $ result = 2;

}elseif($a=='1'){

        $result=3;

      }elseif($a=='01' ;

## A. 1

B. 2

C. 3 D. 4

E. 5

19. Are php function names case-sensitive?

A

, not sensitive

B. Distinguish

20. After the following code is executed, the $result value is:

$x=””;

$result=is_null($x);

?>

A. null

B. true

Cfalse

D、1

21 .Which OOP setup pattern allows a class to be instantiated only once for the entire script?

A. MVC

B. Proxy pattern

C. State pattern

D. Abstract factory pattern

E, Singleton Mode

22. With the help of inheritance, we can create derived classes of other classes. So in PHP, how many parent classes can a subclass inherit at most?

A. 1

B. 2

C. Depends on system resources

D. 3

E. As many as you want

23. Which of the following error types cannot be caught by a custom error handler? ( Double selection) set_error_handler

A. E_WARNING

BE_USER_ERROR

CE_PARSE

DE_NOTICE

24. Execute the following code, the output result is

Abstract class a{

Function __construct(){

Echo “a”;

}

}

$a=new a();

?>

A. a

B. An error warning

C. A fatal error

25. Execute The following code, the input result is

# & LT;? PHP

Class a {

Function __ConStruct () {

## Echo "Echo Classa Something";

}

}

Class b extends a {

Function __ConStruct () {

## Echo "echo classb appearance";

                                                                                                                                                            ​, echoclassbsomethingechoclassasomething

C. echoclassassomething

D

echo class b something

26. Which of the following options does not add john to the users array? 2 points (A) $users[] = 'john'; (B) array_push($users, 'john');

(C )

$users||= 'john';

(D) array_unshift($users, 'john');

27. In PHP, the function of the '+' operator does not include 2 points A. String concatenation

B. Array data merging array(0=> ;1,1=>2)+array(2=>3,3=>4)

C. Addition of variable data

28. Which of the following expressions cannot concatenate two strings $s1 and $s2 into a single string? ( )

A.$s1+$s2

B. "{$s1}{$s2}" C.$s1.$s2

D. implode(' ',array($s1,$s2)) E. All the above methods can be implemented

29. After the following script is run, what is the value contained in the $array array? ( )

$array = array('1','1'); foreach($array as $k=>$v){

$v = 2;

}

A.array('2','2')

B.array(

'

1

'

,

'1') C.array(2, 2) D.array(Null,Null) 30.What is the function of array_shift() function? A Add an element to the array B

Remove an element from the array

C Exchange an array The key and value

array_flip()

D Clear an arrayFill in the blanks

1. Execution program segmentwill output___0_.

*2. To install PHP as an Apache module, first use the statement__

LoadModule php5_module"F:/wamp/php-5.2.6-win32/php5apache2_2 in the file httpd.conf. dll"

__ dynamically loads the PHP module, and then uses the statement__ AddTypeapplication/x-httpd-php .php__ to cause Apache to process all files with the extension php as PHP scripts .

3. The attributes of the class can be serialized and saved in the session, so that the entire class can be restored later. The function used is _serialize___.

4, __debug_backtrace___ function can return the name of the function called in any line in the script. This function is also often used in debugging to determine how the error occurred.

5. ok"; $cd .= "ok";

echo$cd; echo $cd;

?>

The output of this code is ___

abcdeok

____

Reading question

1, (5 points) Please point out the errors in the following code (circle them and correct them)

          function baz($y

,

$a) {                     /$x =new Array();                                                                                                                                                        xas $key =

>

$value) {

                  echo$key + “ ” + $value + “
”;

                                                                                                                                                                        ;  $c=40;                                                                                   use   with  --                                            

               

                                                                                                                                                          ’                                               ‐ to 3. 3-D 3-D 3- What 1 point will the following program output?

 $num = 10;

 function multiply(){

    $num = $num * 10;

 }

 multiply();

 echo $ num;

10

4. Please write the execution result of the following PHP code for 6 points

        $var1 = 5;      $var2 = 10;

       functionfoo(&$my_var){

         global$var1;

            $var1 + =2;

                $var2 = 4                         $my_var +=3;    my_var = 5;

echofoo($my_var) ."\n";

//4

echo $my_var."\n" ;

//8

echo $var1."\n";

//7

echo $var2."\n";

//10

$bar = 'foo';

$my_var = 10;

echo$bar($my_var) ."\n";

//4

5. Write the output of the following code:

function myfunc($argument){

echo $argunment + 10;

}

$variable =10;

echo “myfunc($variable)=".myfunc($variable);

   20myfunc(10)=

6. Write the output result of the following program (5 points)

$test='aaaaaa';

$abc=&$test;

unset($test);

echo $abc;// aaaaaa

7. Write the result of running the program

$a=0;

$b=0;

If($a=3||$b=3){

$a++; //true++

$b++; //0++

}

Echo$a.”,”.$b; //1,1

##  

  $a =0;

$b=0;

If($a=(3|$b=3)){

$a++;//3++

                                                                                                                                                  

#Results: 1._______1,1__________, 2._______4,4____________ 8、

< ;?php

                                                                                                                                                                                                                 .

                                                                                                                                     -                                                        What is the value of the variable $data after a loop ends? please explain.

Question 2: After the program is executed, what is the value of the variable $data? please explain.

Questions and Answers

1. How to intercept Chinese text strings without garbled characters. (3 points)

mb_substr()

2. Output the user’s IP address and determine whether the user’s IP address is 192.168.1.100 --- Between 192.168.1.150 (5 points).

Ip2long("192.168.1.100") ip2long('192.168.1.150')

3. Continuously write a line of "Hello World" string in the header of the file hello.txt. The code is required to be complete (10 points)

$str = File_get_contents("hello.txt ”);

##$str = “helloworld”.$str;

##File_put_contents ("hello.txt",$str);

4. Please list the syntax of three PHP array loop operations and indicate the syntax of each loop. Advantages and Disadvantages 5 points

For 

Can only loop through consecutive index arrays

Foreach

can loop through all arrays

While similar to for

##While (list($key,$val)=each($arr))                                                     Poor readability, low efficiency

5. Find the difference between two dates, such as the date difference between 2007-2-5~2007-3-6 (5 minutes)

(Strtotime( '2007-3-6')-Strtotime("2007-2-5"))/(3600*24)

6. Please change the 2D The array is reordered according to the length of the name, and the ids are assigned in order (starting from 1). (15 points)

$array = array(

                array('id' => 0,'name' => '123'),

array( 'id' => 0,'name' => '12345'),

            array('id' => 0,'name' => '1234'),

array('id' => 0,'name' => '123abcd'),

        array('id' => 0,'name' => '123456'),

);

)

##for($j=0,$c=count($array);$ j<$c;$j++){

## for($i=0;$i<$c-1-$j;$i++){

## If(strlen($array[$i]['name'])>strlen($array[$i+1]['name'] )){

##                                                                                                    array[$i]= $array[$i+1];

##                                       $array[$i+1]= $tmp;

                                                                                                                                                                                                                              through #                                                                   $array[$c-1-$j]['id']= $c-$j;

                                                                             ##$arr ​​= array();foreach($Tarray as $k=>$v)

{

$arr[$k] = strlen( $v['name']);}natsort($arr);$arr1 = array();$i = 0;

foreach($arr as $k =>$v)

{                                                                                                 using   using  -                                                              'name']; $i++;}

8. What is the function of error_reporting in PHP? (1 point)

Change the error level

9. Briefly describe how to get the current execution script path, including the obtained parameters. (2 points)




$_SERVER['REQUEST_URI']



10. Between mysql_fetch_row() and mysql_fetch_array What's the difference? (1 point)



Mysql_fetch_row()

Returns the index array

Mysql_fetch_array()

Returns an array with index and association

11. What is the GD library used for? (1 point)

Dynamicly generated images

12. Please explain the difference between passing by value and passing by reference in PHP. When to pass by value and when to pass by reference? (2 points)

Pass by value: Only the value will be passed to a variable

Passing address: The address will be passed to a variable. At this time, both variables point to the same address at the same time. If one changes, the other will also change.

13. Talk about the advantages and disadvantages of asp, php, jsp (1 point)

Asp.netAdvantages: Faster development,B/S,C/S

##Asp.netDisadvantages: Platform limitations (windows-IIS), high cost

##PHP Advantages: cross-platform, high development efficiency, open source

PHPDisadvantages: Cannot doC/S mode software (for example: QQ)

JSPAdvantages : Wider coverage (C/S,B/S), safer

JSPDisadvantages: Not open source, not free, high cost

14. Use PHP to write the code to display the client IP and server IP 1 point)

$_SERVER['REMOTE_ADDR']

$_SERVER['SERVER_ADDR']

15. What is the difference between margin and paddin in CSS? Write down the direction of the parameters when padding has three parameters and four parameters.

Margin:1px 2px 3px

Margin:1px 2px 3px 4px16. In the development project, If you need to upload a file exceeding 8M, please describe the configuration items that need to be modified in php.ini. (10 points)

upload_max_filesize upload_max_filesize

##post_max_size post_max_size

17. Does Php have any security issues? If so, please list and explain.

Sql

Injection, preprocessing

18. PHP default starting from PHP4.2.0 Configuration Set the register_globals configuration to off. Please indicate the role of this setting and its impact on PHP-related programs. (5 points)

will automatically receive the parameters

index.php?id=1

$id

can be received

$_SESSION['id'] = 1

19.Apache uses process management or thread management by default? How to determine and set the maximum number of connections?

Process Management

20. Two ways of how to execute shell in PHP

Shell_exec

``

21. Write a function, the parameters are year and month, the output result is the number of days in the specified month

Function getDays($year,$ month){

Return (strtotime($year.”-”.($month+1).”-1”)-strtotime($year. ”-”.$month.”-1”))/(3600*24);

##}

22. Use PHP to write a code that does not use the third variable, exchanges the values ​​​​of $a, $b, and sets the initial values ​​​​of $a, $b yourself.

$a = array($a,$b)

$b = $a[0];

$a = $a[1]

23. The difference between interface and abstract class in object-oriented and application scenarios

Interface: It is a special case of abstract class. It does not allow attributes, only constants, and all methods are abstract methods

Abstract class: Not all methods are necessarily abstract methods

Same: None can be instantiated

1 The interface is the core, which defines what is to be done, including Many methods, but no definition of what these methods should do.
2 If many classes implement a certain interface, then each one must use code to implement those methods
3 If the implementations of certain classes have something in common, you can abstract an abstract class and let the abstract class implement it The common code of the interface, while those personalized methods are implemented by each subclass.

Related recommendations:

Detailed explanation of php basic paging code

Summary of php basic knowledge (necessary for novices)

The difference between PHP basics and JavaScript operations (Collection)

The above is the detailed content of PHP basic question and answer knowledge summary sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn