|
PHP |
Java |
file format |
<%%> or <%php%> The code is contained inside the Save as . php file |
write directly Save as . Java file |
language Type |
Instant Compile execution |
Static compilation Execution |
Notes |
PHP exclusive # This is also a single-line comment the same point as Java: //&NBSP; This is a single-line comment This is a multiline comment block multiline */ |
|
variable naming |
PHP Exclusive variable to $ The beginning of the symbol, followed by the name of the variable Same as Java:
variable names must begin with a letter or underscore variable names cannot start with a number variable names can contain only alphanumeric characters and underscores ( A-Z,0-9 and _) variable names are case sensitive ($y and $Y are two different variables)
|
|
|
php is a weak type, used directly when needed, Do not declare function test () { $x = ten; echo $x; } detailed how to use /http www.w3school.com.cn/php/php_variables.asp |
strongly typed, need to declare type and initialize public void Test () { int x =10; system.out.println (x); } |
Simple Output |
echo $x; or var_dump ($x) |
System.out.println (x); |
Variable Type
|
strings, integers, floating-point numbers, logic, arrays, objects, NULL. Although PHP does not specify the type in the variable declaration, but there are these types on the mechanism of the language
|
|
Normal Array |
$goods = Array (" item 1", " item 2"); Use $goods [0], Get " Product 1 " Get Array length echo Count ($goods); |
string[] goods = new string[]{ Item 1 "," item 2 "} Use Goods[0], Get " Product 1 " Get Array length System.out.println (goods.length); |
Associative Arrays |
$goodsInfo = array ("id" = "xxxx", "name" = " product 1", "price" = "20.00"); How to use: $goodsInfo ["id"]; |
in the Java does not have an associative array in it, you want to implement similar functions only using Map map<string,string> goodsinfo = new hashmap<string,string> (); goodsinfo.put ("id", "xxxx"); goodsinfo.put ("name", " item 1"); goodsinfo.put ("Price", "20.00"); How to use: goodsinfo.get ("id"); |
Associative array traversal |
foreach ($goodsInfo as $key = = $val) { echo " Product attributes: ". $key.", values: ". $val; echo "<br/>"; } Output Result: Product attributes: ID, values: xxxx ... The following ellipsis |
for (String Key:goodsInfo.keySet ()) { string str = String.Format (" Commodity properties: %s, key,goodsinfo.get (key)); system.out.println (str); } output result: value: xxxx |
operator |
too much, too lazy to write, see for yourself http://www.w3school.com.cn/php/php_operators.asp |
|
Logical Conditions |
If If Else If ElseIf Else Switch for while these are the same, there is nothing to say, said a PHP in, and Java not in the Foreach this and JS only applies to arrays, and is used to iterate through each key in the array. / value pairs. for normal arrays foreach ($array as $value) { Direct use of $value } for associative arrays, the example is referenced in the above associative array foreach ($array as $key = = $value) { Direct use of $key and $value } |
|
function |
and the JS in the same way, it's not written here and Java the difference. |
|
built-in global variables |
PHP mainly used in Web , so there are many global variables built in, and Java used in Request get the same, specific explanations look at the Web page http://www.w3school.com.cn/php/php_superglobals.asp |
|