Php Study Notes (1)

Source: Internet
Author: User
1. the execution operator is a backslash (''), which is equivalent to the shell_exec () function. Run the $ out 'dir' command to list the current directory and file information. define the constant define (str, thisisaconstvariableBR); echostr; 3. the string is enclosed in single or double quotation marks. The difference is that when a variable appears in double quotes, it is replaced with a variable.

1. the execution operator is a backslash (''), which is equivalent to the shell_exec () function. Run the $ out = 'dir' command to list the current directory and file information. define the constant define (str, this is a const variableBR); echo str; 3. the string is enclosed in single or double quotation marks. The difference is that when a variable appears in double quotes, it is replaced with a variable.

1. The execution operator is a backslash (''), which is equivalent to the shell_exec () function and runs a system command.

$ Out = 'dir'; // list the current directory and file information

2. Define Constants

define("str","this is a const variable
");echo str;

3. String

Enclosed in single or double quotation marks. The difference is that when a variable appears in double quotes, it is replaced with the variable value.

$ A = 10; echo ("variable is $ a"); echo ('variable is $ A'); // The result is: variable is 10 variable is $


4. Accept data

Use the variable $ _ POST to read form data. If the control's name attribute is c1, use the following method to obtain its value:

$ _ POST ['c1']

Index. php file

 

ShowInfo. php file

If (isset ($ _ POST ['submit ']) & $ _ POST ['submit']) {echo ("
Username: ". $ _ POST ['username']."
");}

5. Accept the parameter information in the URL

PASS Parameters in the URL in the format:

Http: // URL/Webpage file? <参数1> = & <参数2> =

Accept parameter: use variable:$ _ GET ['parameter name']

SubmitShowInfo. php file echo ("name:". $ _ GET ['name']."
"); Echo (" sex: ". $ _ GET ['sex ']);

6. Define an array

Array ([key =>] value

,...

)

The keyword can be an integer or a string. If the keyword is omitted, the next digit is used as the keyword, starting from 0.

$ Arr = array ("first" => "Cpu", "disk", 2 => "memory", "screen"); print_r ($ arr); // result: array ([first] => Cpu [0] => disk [2] => memory [3] => screen)

Multi-dimensional array

$ Arr [0] [0] = "CPU"; $ arr [2] [3] = "memory"; print_r ($ arr); // result: array ([0] => Array ([0] => CPU) [2] => Array ([3] => memory ))

7. array Functions

Print_r ($ arr );// Output Array

$ Tmp = array_change_key_case ($ arr, CASE_LOWER); // OR CASE_UPPER

Returns an array of all string keywords in lowercase or upper case.

$ Tmp = array_count_values ($ arr );

Count the number of times all values appear in the array and return the result to another array.

Array_fill:Fill the array with the specified value

Array_fill (int start_index, int num, value );

$ Arr = array_fill (2, 2, "element"); print_r ($ arr); Result: Array ([2] => element [3] => element)

Bool array_key_exists (key, $ arr );// Check whether the specified keyword in the array exists

$ Tmp = array_keys ($ arr [, value]);// Returns an array listing all keywords. If value is specified, only the keyword of value is returned.

$ Tmp = array_merge ($ arr1, $ arr2 ,...);// Combine multiple numbers. If the keywords are the same, the previous one will be overwritten.

Array_pop ($ arr );// Bring up the last element of the array

Array_push ($ arr, value1, value2 ,...);// Press multiple elements to the end of the array, and numbers are used as keywords.

Array_reverse ($ arr );// Reverse array Arrangement

$ Tmp = array_sum ($ arr );// Sum of Elements

Array_unique ($ arr );// Delete repeated elements in the array

Arsort ($ arr );// Sort in descending order

Asort ($ arr );// Sort in ascending order

8. traverse the Array

$ Arr = array ('A' => 'A', 'B' => 'B', 'C' => 'C', "CPU", "memory ", '4'); foreach ($ arr as $ val) {echo $ val. "";} // OR: for ($ I = 0; $ I
 
  

The results of the two methods are as follows: a B c CPU memory 4

Sizeof ($ arr)Get the number of array elements,Next ($ arr)The function moves the pointer to the next position,Current ($ arr)Obtains the elements under the current pointer.

9. Variable Length Parameter List

When defining a function, no parameter is specified. In the function body, obtain parameter information through the following three functions:

Func_num_args ():Number of returned Parameters

Func_get_arg ($ I):Returns the parameter with subscript I.

Func_get_args ():Returned parameter Array

Function sum () {$ num = func_num_args (); $ sum = 0; for ($ I = 0; $ I <$ num; $ I ++) $ sum = $ sum + func_get_arg ($ I); echo "the sum is $ sum
";}Or: function sum () {$ num = func_num_args (); $ sum = 0; $ arg_list = func_get_args (); for ($ I = 0; $ I <$ num; $ I ++) $ sum = $ sum + $ arg_list [$ I]; echo "the sum is $ sum
";}

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.