Comparing PHP and JavaScript, PHP and JavaScript are also dynamic languages, but there are still many differences between them. Here is a comparison.
JavaScript PHP
| The variable name can start with $ or a letter. |
The variable name must start with $. |
| Variable definitions generally use the var keyword. |
Variable definition does not require var |
| The effect of a string using single quotes and double quotes is the same. |
The string is not escaped with single quotes and double quotes. |
| Logical operators are in the format of & | |
Logical operators include & | And Or, And they have different priorities. |
| The semicolon at the end of the statement can be omitted. |
The semicolon at the end of the statement cannot be omitted. |
| Unicode supported for strings |
Unicode is not supported for strings. |
| + Is used to connect the string. |
Concatenate a string with a. number. |
| You can directly use global variables in a function. |
To use global variables in a function, you must first declare them with the global keyword. |
| Returns the nth character of a string using str. charAt (n) |
Use str [I] to obtain the nth character of a string. |
| Arrays for ordered indexing and objects for unordered indexing |
Arrays can be used for both ordered and unordered indexes. |
| Join all elements of the array using the join function |
Use the implode function to connect all elements of the array. |
References:
[1] ECMAScript standards
[2] PHP official manual