Home > Article > Backend Development > What is the difference between php and js
There are differences between PHP and JS in the way of embedding pages, output syntax, data types, defining variables, string splicing, and type conversion
Embedded page method
JS embedding method:
<script></script>
PHP embedding method:
<?php ?>(常用)
Output syntax
Javascript Output
alert("警告的内容") prompt("提示的内容") document.write()(页面输出内容)
PHP output
echo(常用)//可同时输出多个字符串 print //只能输出一个字符串 print_r();//可以打印数组 var_dump();//可输出变量的内容、类型和长度
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 variable
JS Define variables:
var a = 10;
Note: If you define an integer or decimal variable, the value after the equal sign is written directly; if you define a string variable, the value after the equal sign needs to be enclosed in double quotes or single quotes)
PHP defines variables:
$a = 5; $a = "hello"; $a = <<<A
Note: If you define an integer or decimal variable, the value after the equal sign is written directly; if you define a string variable, the value after the equal sign needs to be enclosed in double quotes or single quotes. )
String splicing
String splicing in JS:
" "; eg: "hello" "world"
String splicing in PHP:
"."; eg: "hello"."world"
Type conversion
Type conversion in JS
转化为整数:parseInt(); 转化为小数:parseFloat(); 判断是否为合法数字类型:isNaN();
Type conversion in PHP
$a = (Int)$a; //强制转化变量a为整数 $b = settype($b,"string"); //强制转化变量a为字符串
The above is the detailed content of What is the difference between php and js. For more information, please follow other related articles on the PHP Chinese website!