Skip to content

Instantly share code, notes, and snippets.

@summer10920
Last active May 11, 2020 15:39
Show Gist options
  • Save summer10920/daff1ebc7ae0390501811827cedad0ac to your computer and use it in GitHub Desktop.
Save summer10920/daff1ebc7ae0390501811827cedad0ac to your computer and use it in GitHub Desktop.
20200508-php-baseclass-1
<!DOCTYPE html>
<html lang="tw">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>我的第一堂課</title>
</head>
<body>
<h3>HTML與PHP的關係+註解</h3>
<P>這一行是由HTML產生</P>
<!--
HTML的註解
可以單行或多行
-->
<?php
echo "<p>這A行由PHP產生,包含p標籤</p>"; //echo 為輸出的意思
echo "<p>這B行由PHP產生,包含p標籤</p>"; //這裡註解只能單行
/*
PHP的註解
可以單行或多行
*/
echo "<p>這C行由PHP產生,包含p標籤</p>";
?>
<?= "<p>這是另一種的PHP產生,省略的echo行為</p>" ?>
<hr />
<h3>變數的文字串</h3>
<?php
$what = "冷笑話"; //將文字存到變數去,用""標記起來,讓程式知道這是文字不是指令
$title = "<b>" . $what . ":</b> "; //變數可以跟文字合併再一起,用.來穿接,也能再丟給一個變數
print($title); //輸出方式2
$who = "小明";
$where = "超商";
$why = "為什麼";
$when = "繳費";
$how = "坐輪椅?";
print $why . $who . "去" . $where . $when . "後,出來卻要" . $how; //輸出方式3
?>
<hr />
<h3>變數的數學計算</h3>
<?php
/*將數字計算結果到$a儲存起來,最後把$a資料印出 */
$a = 7 + 5; //這裡把+抽換變成-*/試試
$a = 7 - 5; //2
$a = 7 * 5; //35
$a = 7 / 5; //1.4
$a = 13 % 5; //3,餘數
echo $a; //32~36行都是同個變數$a,一直被重新覆蓋新的結果,所以37行只會執行最後一行
/*還有很多用法,譬如四捨五入,無條件進位捨去等等,有興趣可以去查*/
?>
<br>
<?php
/**數字型的變數也可以拿來計算 */
$b = 5;
$b = $b + $a; //變數可以跟變數做數學計算,如果都是數字的話,這裡是5+3
print($b); //8
?>
<br>
<?php
/* 變數的自身變化*/
$c = 10;
$c = $c + 5; //對自己做數學,再重新記住自己為新內容,此時值為15
$c = $c - 5; //此時值為10,跟$a不同的邏輯。$c一值有被翻新值,$a則是一值被覆蓋新值
$c = $c * 5; //50
echo $c;
?>
<br>
<?php
/*
不同的快速技巧與深奧邏輯
這裡需要認真聽課說明唷,筆記不方便說明
*/
$d = 5;
echo $d + 5; //10
echo ",";
echo $d += 5; //10
echo ",";
echo $d += 1; //11
echo ",";
echo $d++; //11
echo ",";
echo $d; //12
echo ",";
echo ++$d; //13
echo "<br>";
?>
<hr />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment