Basic PHP syntax and data types:
(1) Basic PHP syntax:
1. Htm and php mix
2. A statement ends with ; (semi-colon)
3. How to define a variable and use it
(2) PHP data operation type
Four scalar types:
boolean (boolean type) is understood as true or false
integer (integer)
float (float, also called "double")
Understand as a decimal
string (string)
Two composite types:
array (array)
object(object)
boolean (boolean type) is understood as true or false
$bo=TRUE; $bo=FALSE;
integer (integer)
$bo=1; $bo=-12;
float (float, also called "double") is understood as a decimal type
$bo=1.001; $bo=3.1415926;
string (string)
$bo="This string or EN Word";
array (array)
$bo=array(1,2,3,4); $bo=array(“A”=>1 , “B”=>2);
Here is my first php program source code:
Copy the codeThe code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<html xmlns="http:///1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>First PHP Program</title>
<style type="text/css"><!--
body,td,th {
font-size: 12px;
}
body {
margin-left: 10px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
}
--></style><style type="text/css" bogus="1">body,td,th {
font-size: 12px;
}
body {
margin-left: 10px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
}</style></head>
<body style="text-align:center" style="text-align:center">
<span style="font-size:36px;color:blue;font-family:Chinese running script" style="font-size:36px;color:blue;font-family:Chinese running script">Welcome to the world of PHP! ! !</span>
<?php
$name="CHAUVET";
$iValue="9999";
$fValue=9.9900;
$bValue=true;
$aValue=array(1,2,3,4);
print "<br/>";
echo "Hello world,";
echo $name;
print "<br/>The value of iValue is";
print $iValue;
print "<br/>The value of iValue is";
print $fValue;
print $bValue;
print "<br/>bVlue's judgment<br/>";
if($bValue)
{
echo "The value of bVlue is true";
}
print "<br/>The value of aVlue is";
for($i=0;$i<4;$i++)
{
echo $aValue[$i];
}
?>
</body>
</html>
Introduction and application of commonly used PHP operations types
1. Arithmetic operations
example:
5 * 6 - 12
2*(28+1)
Note: Arithmetic operations follow mathematical operations rules
From left to right, first calculate multiplication and division and then add or subtract. When encountering brackets, first calculate inside brackets.
2. Assignment operation
example:
$a=1;
$a+=2;
$a*=3;
Note: Assign the value to the left variable.
3. Comparative operations
example:
1==2
3!=2
5<3
"ok"=="ok"
1==='1'
Note: The value obtained by the comparison operation is a Boolean value
4. Logical operations
example:
1 && 1
0 && 1
1 || 1
1 || 0
5. Increase and decrease operations
example:
$a++
++$a
$a--
--$a
php source code:
Copy the codeThe code is as follows:
<title>Output Table</title>
<?php
echo "<table border='1' width='300'>";
for($i=0;$i<4;$i++)
{
echo "<tr>";
for($j=0;$j<4;$j++)
{
echo "<td>";
echo $j+1;
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
?>
<title>Output Table</title>
<?php
echo "<table border='1' width='300'>";
for($i=0;$i<4;$i++)
{
echo "<tr>";
for($j=0;$j<4;$j++)
{
echo "<td>";
echo $j+1;
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
?>
Operator:
Copy the codeThe code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<html xmlns="http:///1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>php operator</title>
<style type="text/css"><!--
body,td,th {
font-size: 12px;
}
body {
margin-left: 10px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
}
--></style><style type="text/css" bogus="1">body,td,th {
font-size: 12px;
}
body {
margin-left: 10px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
}</style></head>
<body style="text-align:center" style="text-align:center">
<?php
//The programming language of addition, subtraction, multiplication and division does not have
print (1+3)*5;
echo "<br/>";
print (3-1)/10;
print "<br/>";
//Assignment operation
$val=3;
$val+=5;//equivalent to $val=$val+5
$val*=10;
echo "val value is:";
print $val;
print "<br/>";
//Compare operations
if(1==1&&5>3){print "Logistics and one false are false<br/>";}
if(3!=2||"ok"=="ok"){print "Logical or one true is true<br/>";}
/*Increment and decreasing operations*/
$value=8;
echo $value++;#8 is also annotation
print "<br/>";
echo $value;#9
print "<br/>";
print ++$value;#10
echo "<br/>";
echo --$value;#9
?>
</body>
</html>
Previous page12Read the full text