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";
public 返回值 函数名(参数){ // sth; }
function 函数名(参数){ //return 决定是否有返回值 }
PHP: A structure similar to
__XXX__, such as
__LINE__ (current line)
class A{ public A(){} }
class A{ function __construct($name){} }
实例.方法();
实例->方法();
final int TAG = 1001;
const TAG = 1001;
Java:
super.方法();
parent::方法();
class A{ public static int a = 10; } // 访问方式: A.a
class A{ public static $a = 10; } // 访问方式: A::$a;
Comparison operators:
PHP:
绝对等于:x === y 不等于:x <> y 绝对不等于:x !== y
与:x and y 或:x or y 异或:x xor y
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!