Home > Backend Development > PHP Tutorial > What is the difference between php and js

What is the difference between php and js

清浅
Release: 2023-04-06 13:42:02
Original
3960 people have browsed it

There are differences between PHP and JS in the way of embedding pages, output syntax, data types, defining variables, string splicing, and type conversion

What is the difference between php and js

Embedded page method

JS embedding method:

<script></script>
Copy after login

PHP embedding method:

<?php     
?>(常用)
Copy after login

Output syntax

Javascript Output

alert("警告的内容")
prompt("提示的内容")
document.write()(页面输出内容)
Copy after login

PHP output

echo(常用)//可同时输出多个字符串  
print  //只能输出一个字符串      
print_r();//可以打印数组
var_dump();//可输出变量的内容、类型和长度
Copy after login

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;
Copy after login

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 
Copy after login

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();
Copy after login

Type conversion in PHP

$a = (Int)$a;  //强制转化变量a为整数
$b = settype($b,"string");  //强制转化变量a为字符串
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template