PHP basic knowledge and PHP and JS difference (focus)--4.23

Source: Internet
Author: User

1: Variables and constants
Named
Start with $, the variable's flag, the variable name with a letter, a number, an underscore character, and the number cannot begin.
Scope
By default, the function cannot access the external global variables internally, but can access the super global variables. $_get,$_post, etc.

Uppercase and lowercase
Variables and constants are case-sensitive.
Can I reset its value
Variables can be re-assigned. Once a constant is defined, it cannot be unregistered or re-assigned.

2: function
Parameters
You can declare 0-n, but when invoked, the parameters that are required to be called are the same as the number of arguments at the time of declaration.
The functions in PHP can have default values compared to JS.

3: Logical operators
In PHP, the logical operator returns the result of the operation as a Boolean value

4: Table only son value
Form two methods of passing values: GET POST, method= "Get/post"
Two types of values: Get is displayed on the address bar, post is not displayed in the Address bar.
About the amount of data, get the amount of data to transmit the maximum of about 2K, post theoretically no limit.
For file upload, you have to use post

5: How to get the value on the Address bar in PHP, or the value of post
Answer: $_get,$_post These two super global variables.
Both are arrays.

$_get[name], name refers to the xxxxx in Name= "xxxxx" in the form



6: The procedure of the message book:
Form page for message
Form List Page

Use PHP to collect data, connect to the database, and write to the database.
Use PHP to connect to the database, read the database, and then show it.



Comparison between PHP arrays and JS arrays

/* Create an array in JS
Two different ways
1:var arr = new Array (1,2,3,4);
2:var arr = [n/a];

/*
Creating an array in PHP
*/

$arr = Array (+/-);
Print_r ($arr);

/*
In JS, the index of an array is always incremented starting from 0,
There is no gap in the middle.

But in PHP, the index of the array is very flexible.
Can be a number, or it can be a string,
It can even be a mix of numbers and strings.
*/



/*
If the index part specifies a numeric index,
Another cell does not have an index specified.
The largest numeric index value that has ever appeared before the cell,
Then +1, as its key value
*/

$arr = Array (10=> ' Zhao ',13=> ' money ', ' sun ',99=> ' li ', ' name ' and ' Zhang San Fung ', ' dsafdsafdsaf ' ~ = ' came ');
Print_r ($arr);



/*
In PHP, how to reference the cell values of an array
Key by index,
And the index has "number", "string"
*/

If it is a numeric index
echo $arr [10];

In the case of a string index, the index must be wrapped with ' single quotation marks.
/*
Define (' name ', ' Dsafdsafdsaf ');
echo $arr [name];
*/

echo $arr [' name '];

PHP basic knowledge and PHP and JS difference (focus)--4.23

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.