Differences between basic PHP operations and basic JS operations
Page embedding
JS embedding method: <script> </script>
PHP embedding method: <? Php
?> (Common)
Output syntax
Javascript output
1. alert ("Warning content ")
2. prompt ("prompt content ")
3.doc ument. write () (page output)
PHP output
1. echo (commonly used) // multiple strings can be output simultaneously. For example: echo $ a, "hello ";
2. print // only one string can be output. For example: print $;
3. print_r (); // you can print an array.
4. var_dump (); // The content, type, and length of the output variable.
Data Type
JS Data Type
INTEGER (integer) int
Float with single precision
Double decimal number
Decimal
Boolean bool (only two statuses can be saved)
Datetime
Strong character char (not commonly used)
Strong string (not commonly used)
PHP Data Type
Bool Boolean (storage in two States)
Int integer
Float (double) float
Char character
String
Define Variables
JS-defined variable: var a = 10;
(Note: 1. If you define an integer or decimal variable, directly write the value after the equal sign
2. If a string variable is defined, double quotation marks or single quotation marks are required for the value after the equal sign)
PHP defines variables: $ a = 5; $ a = "hello"; $ a = <A-defined string content // You can also add HTML code;
(Note: 1. If you define an integer or decimal variable, directly write the value after the equal sign
2. If a string variable is defined, double quotation marks or single quotation marks are required for the value after the equal sign)
String concatenation
Concatenation of strings in JS: "+"; eg: "hello" + "world"
Concatenation of strings in PHP: "."; eg: "hello". "world"
Variable features unique to PHP
// Escape Character: It is generally used in strings to output special content.
// \ "Output double quotation marks \ t tab \ n line feed
Eg: $ s = "wo \" rld "; // escape quotation marks $ s =" wo \ trld "; // escape tabulation $ s =" wo \ nrld "; // escape line feed
$ A = "hello ";
// Parse the variable
$ B = "hello {$ a}"; // output hello, hello
Type conversion
Type conversion in JS
1. convert to an integer: parseInt ();
2. Convert to decimal places: parseFloat ();
3. Determine whether the data type is valid: isNaN ();
Type conversion in PHP
1. $ a = (Int) $ a; // force convert variable a to an integer
2. $ B = settype ($ B, "string"); // forcibly convert variable a to a string
Common functions about variables in PHP
$ S = 5;
1. var_dump (empty ($ s); // empty ($ s) determines whether the variable s is null. It can be 0, a null string, or undefined.
2. unset ($ s); // Delete variable s
3. var_dump (isset ($ s); // isset ($ s) determines whether the variable s is defined
Special usage in PHP
1. Get the address of the Variable
$ A = "hello ";
$ B = & $ a; // & represents the address for getting the variable
Echo ($ B); // The output result is hello.
2. Variable
$ S = "hi ";
$ Hi = "hello ";
Echo $ s; // The output is hello.