Detailed explanation of the difference between PHP back-end language and front-end JS syntax

coldplay.xixi
Release: 2023-04-08 18:56:02
forward
2033 people have browsed it

Detailed explanation of the difference between PHP back-end language and front-end JS syntax

Comparison of PHP back-end language and front-end JS syntax

1. Comments are all universal

/ /Single-line comment

/*Multi-line comment*/

2. Define variables

JS: var num = 10;

PHP: $num = 10

3. Print content

JS: console.log(num);

PHP: echo $num;

Note: The code written in the backend cannot be run directly. It can only be placed in the folder corresponding to the server and run through the server.

How to run through the server: Find the server corresponding to the IP address folder, and then find the corresponding file and run

4. How to define the collection

JS: Array

var arr = [1, 3, 5];

arr[0];

PHP: Dictionary (object)

$arr = array(1, 3, 5);

echo $arr[1]

print_r($arr);

5. Loop statement

PHP: if

$age = 16; if($age >= 18){ echo "成年人"; }else{ echo "未成年人"; }
Copy after login

PHP: Sanmu

$res = ($age >= 18) ? "成年人" : "未成年人"; echo $res;
Copy after login

PHP: switch

switch ($age){ case -1: echo "非人类"; break; case 18: echo "成年人"; break; default: echo "未成年人"; break; }
Copy after login

PHP: for

$arr = array(1, 3, 5); for($i = 0; $i < count($arr); $i++){ echo $arr[$i]; echo "
"; }
Copy after login

PHP: while

$index = 0; while ($index < count($arr)){ echo $arr[$index]; echo "
"; $index++; }
Copy after login

Recommended tutorial: "PHP video tutorial

The above is the detailed content of Detailed explanation of the difference between PHP back-end language and front-end JS syntax. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!