Home  >  Article  >  Backend Development  >  Detailed explanation of the difference between PHP back-end language and front-end JS syntax

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

coldplay.xixi
coldplay.xixiforward
2020-06-08 09:32:262061browse

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 "未成年人";
}

PHP: Sanmu

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

PHP: switch

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

PHP: for

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

PHP: while

$index = 0;
while ($index < count($arr)){
    echo $arr[$index];
    echo "<br>";
    $index++;
}

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete