", "!==" operators, Java does not have them."/> ", "!==" operators, Java does not have them.">
Home >Backend Development >PHP Problem >Is there any difference in syntax between php and java?
There are differences in syntax between php and java. Differences: 1. PHP has EOF, but Java does not; 2. The connectors between variables are different, Java uses " ", and PHP uses "."; 3. PHP has magic constants, but Java does not; 4. PHP has "==" =", "<>", and "!==" operators are not available in Java.
Recommended: "PHP Video Tutorial"
There is a difference in syntax between php and java. Let me introduce to you some syntax differences between php and java.
The difference between the basic syntax of PHP and Java. The difference here only distinguishes syntax and does not involve function calls
Java:
int a = 10;
PHP:
$a = 10
This is not available in Java, so I don’t know what this is for yet
PHP:
echo <<<EOF "hello" EOF;
Java:
public final NUM = 10;
PHP:
define("NUM", 10);
Java:
int age = 18; String str = "我今年"+18+"岁";
PHP:
$age = 18; $str = "我今年" . $age . "岁";
About else-if
PHP can be written as elseif
java can only be written as else if
(The difference is the space between else and if)
Java:
// 方式1 int[] arr = new int[3]; arr[0] = 12; arr[1] = 23; arr[2] = 46; // 方式2 int[] arr = {12, 23, 46}
PHP:
The array function is required to declare an array in PHP
// PHP中数组允许插入不同类型的数据 $arr = array("e1", "e2", 23, 45);
Get the array length:
java:
int[] arr = new int[3]; int count = arr.length();
php:
$arr = array("e1", "e2", 23, 45); $arrLength = count($arr);
There is also something called an associative array in php, which is similar to map## in Java #
$array1 = array("key1" => "value1", "key2" => "value2", "key3" => "value3"); $array1["key4"] = "value4"; $array1["key5"] = "value5"; $array1["key6"] = "value6";7. Function declaration methodJava:
public 返回值 函数名(参数){ // sth; }php:
function 函数名(参数){ //return 决定是否有返回值 }8. Magic constantThere is no such thing in Java
PHP: A structure similar to
__XXX__, such as
__LINE__ (current line)
class A{ public A(){} }php:
class A{ function __construct($name){} }11 .Method callJava:
实例.方法();php:
实例->方法();12. Class constantjava:
final int TAG = 1001;php:
const TAG = 1001;13. Execute the method of the parent class:
Java:
super.方法();php:
parent::方法();13. Method static variable Java:
class A{ public static int a = 10; } // 访问方式: A.aphp:
class A{ public static $a = 10; } // 访问方式: A::$a;14. OperatorOnly list the ones that PHP has and Java does not have
Comparison operators:
PHP:
绝对等于:x === y 不等于:x <> y 绝对不等于:x !== yLogical operators:
与:x and y 或:x or y 异或:x xor yand so on....For more programming-related knowledge, please visit:
Introduction to Programming! !
The above is the detailed content of Is there any difference in syntax between php and java?. For more information, please follow other related articles on the PHP Chinese website!