Home>Article>Backend Development> Is there any difference between js and php?

Is there any difference between js and php?

青灯夜游
青灯夜游 Original
2020-09-28 15:12:07 5350browse

There are differences between js and php. The differences are: 1. The string connector of php is ".", and the string connector of js is " "; 2. JS is strictly case-sensitive, and in php Custom function names are not case-sensitive; 3. There is a difference between single and double quotes in PHP, but there is no difference in single and double quotes in JS.

Is there any difference between js and php?

Recommended: "PHP Video Tutorial"

The difference between js and php is:

1. The core functions of the two are different:

The core function in php is implemented using functions, for example, getting the length of a string: $length = strlen(str);

JS is implemented using object methods, such as getting the length of a string: var length = str.length.

2. Variable value transfer methods are different:

In js, the value transfer and address transfer of variables are determined according to the type of the object being passed, and cannot be controlled by oneself;

All types in PHP can freely control whether they are passed by value or by address. Adding & before the variable can become the address method, and not adding & can be the value method.

3. Differences in type conversion

In JavaScript, empty objects and empty arrays are converted into boolean values, which are true; but in PHP, empty objects and empty arrays are converted into boolean values, which are false ( Only in php4, the boolean value of empty objects is false); including non-zero negative values, they are converted to true.

4. The difference between actual parameters

In JavaScript, there is no limit on the number of formal parameters and actual parameters. The number of formal parameters can be greater or less than the actual parameters, but in PHP , an error will be reported if the actual parameter is smaller than the formal parameter, because there are parameters that are defined but not used, which may affect the function of the function in the eyes of the PHP interpretation mechanism.

5. Differences in data types

There is an undefined type in JavaScript, but there is no such type in PHP. Therefore, when a variable is not assigned any value, this type in JavaScript is undefined (use undeclared The variable will report an error), but in php it is the Null type; and there is only a number type in javascript, but there is no such type in php, and it is replaced by the int float type.

6. String connection

The plus sign = is used in JavaScript, and the dot sign is used in PHP..=

7. The difference between control statements

else if and elseif are both supported in php, javascript only supports the former

8. Case issues

javascript is strictly case-sensitive, and custom function names in php are not case-sensitive. When naming a function, you cannot use declared functions or PHP's built-in function names.

9. Static variables

PHP supports declaring function variables as static (static). JavaScript does not have static variables but can define attributes of the function to pretend to be static variables.

Related recommendations:php training

The above is the detailed content of Is there any difference between js and php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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