Home > Backend Development > PHP Tutorial > The difference between PHP basics and JavaScript operations (Collection)

The difference between PHP basics and JavaScript operations (Collection)

黄舟
Release: 2023-03-15 13:56:02
Original
1230 people have browsed it

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:

<script></script>
Copy after login

PHP embedding method:

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

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";

//Parse variables

$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();


Type conversion in PHP

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

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是否定义
Copy after login

Special usage in PHP

1. Variable address

$a = "hello";
  $b = &$a;  //&代表取变量的地址
  echo($b);  //输出结果为hello
Copy after login

2. Variable variables

 $s = "hi";
  $hi = "你好";
  echo $$s;  //输出的是 你好
Copy after login

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template