The following editor will bring you an article that discusses in detail the difference between PHP basics and JS operations (a must-read article). The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor to take a look.
Embedding page method
JS embedding method:
PHP embedding method:
(常用)
Output syntax
Javascript output
1.alert("Warning content" )
2.prompt("prompt content")
3.document.write()(page output content)
PHP output
1.echo (commonly used) //Can output multiple strings eg at the same time: echo $a,"hello";
2.print //Can only output one string eg: print $a;
3.print_r();//You can print the array
4.var_dump();//You can output the content, type and length of the variable
Data type
JS data type
Integer type (integer) int
Single precision decimal float
Double precision decimal double
Decimal decimal
Boolean bool (can only store two states)
Date and time type datetime
Character char (not commonly used) strong
String string (not commonly used)strong
PHP data type
bool Boolean type (storage two types Status)
int integer type
float(double) floating point type
char character
string string string
Define variables
JS defines variables: var a = 10;
(Note: 1. If you define an integer or decimal variable, write the value after the equal sign directly
2. If defined String variable, the value after the equal sign needs to be enclosed in double quotes or single quotes)
PHP definition variable: $a = 5; $a = "hello"; $a = <<
String splicing
String splicing in JS: " +"; eg: "hello"+"world"String concatenation in PHP: "."; eg: "hello"."world"
PHP-specific variables Features// Escape characters: generally used in strings to output special content// \" Output double quotes \t Tab character \n Newline
eg:$s = "wo\"rld"; //Escape quotes $s = "wo\trld"; //Escape tabs $s = "wo\nrld"; //Escape newlines$a = "Hello";
$b = "hello{$a}"; //Output hello, hello
Type conversion
Type conversion in JS
1. Convert to integer: parseInt();2. Conversion For decimals: parseFloat();
3. Determine whether it is a legal numeric type: isNaN();1.$a = (Int)$a; //强制转化变量a为整数 2.$b = settype($b,"string"); //强制转化变量a为字符串
Commonly used functions about variables in PHP
$s = 5; 1.var_dump(empty($s)); //empty($s)判断变量s是否为空,可以为0,可以为空字符串,也可以是未定义 2.unset($s); //删除变量s 3.var_dump(isset($s)); //isset($s)判断变量s是否定义
Special usage in PHP
1. Variable address
$a = "hello"; $b = &$a; //&代表取变量的地址 echo($b); //输出结果为hello
2. Variable variables
$s = "hi"; $hi = "你好"; echo $$s; //输出的是 你好
The above is the detailed content of The difference between PHP basics and JavaScript operations (Collection). For more information, please follow other related articles on the PHP Chinese website!