<?php
echo "Hello test01";
$var = "PHP";
echo "$var";
echo "<br/>";
$var = "JAVA";
echo "$var";
echo "<br/>";
$a = "Apple";
$b = 10;
Var_dump ($a);
Var_dump ($b);
echo "<br/>";
$m = "M";
$M = "M";
echo "$m";
echo "$M";
echo "<br/>";
echo $m 1=memory_get_usage ();
echo "<br/>";
$v 1 = "123";
echo $m 2=memory_get_usage ()-$m 1;
echo "<br/>";
$v 2=123;
echo $m 3=memory_get_usage ()-$m 1-$m 2;
echo "<br/>";
$v 3=123.00;
echo $m 4=memory_get_usage ()-$m 1-$m 2-$m 3;
echo "<br/>";
$v 4=array ("123");
echo $m 5=memory_get_usage ()-$m 1-$m 2-$m 3-$m 4;
echo "<br/>";
$string = "Just be";
Var_dump ($string);
echo "<br/>";
$string = 9494;
Var_dump ($string);
echo "<br/>";
$man = "male";
$flag = $man = = "Male";
Echo $flag;
echo "<br/>";
Var_dump ($flag);
echo "<br/>";
$data _int1=123;
echo $data _int1;
echo "<br/>";
$data _int2=-123;
echo $data _int2;
echo "<br/>";
$data _int3=0123;
echo $data _int3;
echo "<br/>";
$data _int4=0x123;
echo $data _int4;
echo "<br/>";
$num _float1=1.234;
echo $num _FLOAT1;
echo "<br/>";
$num _float2=1.2e3;
echo $num _float2;
echo "<br/>";
$num _float3=7.0e-3;
echo $num _FLOAT3;
echo "<br/>";
$str _string1= ' I am a string ';
$str _string2= "I am also a string";
echo $str _string1;
echo "<br/>";
echo $str _string2;
echo "<br/>";
$file _handle=fopen ("1.txt", "R");
if ($file _handle) {
while (!feof ($file _handle)) {
$line =fgets ($file _handle);
Echo $line;
echo "<br/>";
}
}
Fclose ($file _handle);
echo "<br/>";
error_reporting (0);
$var;
Var_dump ($var);
echo "<br/>";
$var 1=null;
Var_dump ($var 1);
echo "<br/>";
$var 2=null;
Var_dump ($var 2);
echo "<br/>";
$var 3 = "Happy Birthday";
Unset ($var 3);
Var_dump ($var 3);
echo "<br/>";
$p = "PII";
Define ("PI", 3.14);
Define ($p, 3.14);
Echo PI;
echo "<br/>";
Echo PII;
echo "<br/>";
$r = 3;
echo "Mianji:". (pi* $r * $r). " <br/> ";
echo "Zhouchang:". (2*pi* $r). " <br/> ";
echo "<br/>";
Echo _file_;
echo "<br/>";
Echo _line_;
echo "<br/>";
Echo php_version;
echo "<br/>";
Echo Php_os;
echo "<br/>";
$p = "";
Define ("PI1", 3.14);
Define ("PI2", 3.142);
$height = "M";
if ($height = = "M") {
$p = "PI1";
}else if ($height = = "T") {
$p = "PI2";
}
$r = 2;
$area =constant ($p) * $r * $R;
Echo $area;
echo "<br/>";
$is 1=defined ($p);
$is 2=defined ("PI3");
Var_dump ($is 1);
Var_dump ($is 2);
echo "<br/>";
$a =1; $b = 2;
$c = $a + $b;
Echo $c;
echo "<br/>";
$a = 1;
$b = "1";
Var_dump ($a = = $b);
echo "<br/>";
Var_dump ($a = = = $b);
echo "<br/>";
Var_dump ($a! = $b);
echo "<br/>";
Var_dump ($a!== $b);
echo "<br/>";
$a = 78;
$b = $a >=60? " Yes ":" No ";
Echo $b;
echo "<br/>";
$a =true;
$b =true;
$c =false;
$d =false;
Echo ($a and $b)? " Y ":" N ";
echo "<br/>";
Echo ($a or $b)? " Y ":" N ";
echo "<br/>";
Echo ($a xor $c xor $d)? " Y ":" N ";
echo "<br/>";
Echo, $c? Y ":" N ";
echo "<br/>";
echo $a && $d? " Y ":" N ";
echo "<br/>";
echo $a | | $c | | $d? " Y ":" N ";
echo "<br/>";
$conn [email protected]_connect ("localhost", "username", "password");
echo "error,the reason:". $php _errormsg;
echo "<br/>";
$sex = "male";
if ($sex = = "Male") {
echo "Yes";
}else if ($sex = = "female") {
echo "No";
}
echo "<br/>";
$num =rand (1,5);
$info = "";
Switch ($num) {
Case 1:
$info = "1";
Break
Case 2:
$info = "2";
Break
Case 3:
$info = "3";
Break
Default
$info = "No";
}
Echo $info;
echo "<br/>";
echo "<br/>";
$sum = 12;
echo "Hungry";
echo "<br/>";
while ($sum <100) {
$num =rand (1,20);
$sum = $sum + $num;
if ($sum <100) {
echo "not";
echo "<br/>";
}
}
Echo $sum;
echo "<br/>";
$students =array (
' 2001 ' = ' A ',
' 2002 ' = ' B ',
' 2003 ' = ' C ',
' 2004 ' = ' D ',
' 2005 ' = ' E ',
);
foreach ($students as $student) {
Echo $student;
echo "<br/>";
}
echo "<br/>";
$grades =array (
' =>array ' (' A ', ' 33 '),
' =>array ' (' B ', ' 44 '),
' =>array ' (' C ', ' 55 '),
' =>array ' (' D ', ' 66 '),
' =>array ' (' E ', ' 77 '),
);
foreach ($grades as $key = = $val) {
Echo $key;
echo ":";
foreach ($val as $v) {
Echo $v;
}
echo "<br/>";
}
?>
PHP Basic Syntax