SlideShare a Scribd company logo
PHP - part I

Ensky / 林宏昱
Client – Server Recall


       HTTP Request



      HTTP Response
      + BODY(HTML)
Server Implement
1. 建立連線(socket),等client進來
2. Client進來 -> 分析HTTP Request,
   找出URL、Host、Cookie等等資訊
3. 根據上述資訊開始產生所需資料
4. 將產出的資料丟回Client
Server Implement
1. 建立連線(socket),等client進來
2. Client進來 -> 分析HTTP Request,   拆出來!
   找出URL、Host、Cookie等等資訊
3. 根據上述資訊開始產生所需資料
4. 將產出的資料丟回Client
Server Implement
1. 建立連線(socket),等client進來
2. Client進來 -> 分析HTTP Request,   Web
   找出URL、Host、Cookie等等資訊         Server
3. 根據上述資訊開始產生所需資料
                                  CGI
4. 將產出的資料丟回Client
Server Implement

             HTTP Request


HTTP         Web server     stdin + env
Response
+ BODY
               stdout         CGI
CGI Implement
include <iostream>
using namespace std;
int main () {
    cout “<!doctype html>”;
    cout “<html>”;
    cout “    <head>”;
    ...以下略
}
Any better choice?
We Save Your Time!
我今天要講的是…
HELLO WORLD!
<?php
  echo “hello world!”;
?>

OR

hello world!
PHP is a programming language
PHP是某個人用C寫CGI寫到快吐血,
憤而寫出的程式語言

既然是程式語言,所有C++、JAVA、
Python、…,他們能做到的事情,PHP基本上
都辦得到

你可以用它來寫Web server、BBS抓魚機器人、
Hadoop程式、NP作業…XD
PHP is a Interpreted language
No need to compile, PHP will compile then
execute.

不用compile的意思是他會在「每次」request
進來的時候compile,無論你有沒有改過那個
檔案。
  – 很慢

所以我們通常會安裝一些快取OP code的外掛
PHP 的型態
• 基本型態如下
 – Boolean ( True / False )
 – Integer
 – Float
 – String (“abc” ‘cde’)
• 複雜型態如下
 – Array
 – Object
PHP 是個寬鬆型態的語言
• 變數在使用前不需宣告他的型態
 $a = “this is a string”


• 變數會自動轉換型態
 $a = “1”; //String
 $b = $a + 1; //Integer
PHP 是個寬鬆型態的語言
• 自動轉型好規好,有他的問題在
 var_dump(“” == 0); // bool(true)
 var_dump(“0” == 0); // bool(true)
 var_dump(“0” == “”); // bool(false)

• 因此很多的時候我們會需要
  「連型態一起判斷」的判斷式                ===
 – var_dump(“” === 0); // bool(false)

• 強制轉型的方法和c++一樣,在此不多提
Variable Scope in PHP
C++裡面的scope

for ( int i = 1; i <= 5; i++ ) { do something… }
cout << i << endl;


//這裡會錯,他會說i在這個scope裡面
Variable Scope in PHP
PHP裡面的scope
• in Global
  最外面的變數都是global 變數

• In function
  在function內的變數都是local變數,沒有內
  層scope。
Variable Scope in PHP

要取用global變數有兩種方法,
假設現在有$a, $b在global裡面
function I_want_to_use_global_var ()
{
    global $a;
    $a = ‘x’;
    $GLOBALS[‘b’] = ‘y’;
}
Operator in PHP
• 大家都會的
  +, -, *, /, %, ++, --
  <, <=, >, >=, ==, ===, !=, !==
  &&, ||
  其中,&&也可以寫成AND, ||也可以寫成OR


• 字串連接用「.」
  “this is a “ . “string”
Operator in PHP
• 變數和字串的連接有幾種方式
  $a = 123;
  $b = “this is a number: ” . $a;
  $b = “this is a number: {$a}”;

• 我個人比較偏好前一種,因為可以放運算
  式。
String in PHP
PHP中,字串可以用單引號或雙引號包起來,
但兩者在PHP中意義不同
• 單引號包起來的字串,寫什麼就是什麼
$a = 123;
echo ‘ $a is 123n haha ’;
// $a is 123n haha

• 雙引號包起來的字串,會幫你轉換變數、換行符號
  等等
echo “ $a is 123n haha ”
// 123 is 123
// haha
Function in PHP
• PHP的function很直覺使用
 function is_even ($n) {
    return $n % 2 == 0;
 }
 echo is_even(1); // 0

• PHP的function也可以是個值
  $is_even = function ($n) {
     return $n % 2 == 0;
  }
  echo $is_even(2); // 1
Function in PHP
• PHP function 的參數可以有預設值
function print_something ($str=‘a’)
{
     echo $str;
}
print_something(‘123’); // 123
print_something(); // a
Take a break
Array in PHP
• 可以像你平常用的array
$scores = [60, 59, 70];
print_r($scores);
/*
Array
(
    [0] => 60
    [1] => 59
    [2] => 70
)
*/
echo $scores[1]; // 59
Array in PHP
• 可以當queue或stack來用,超爽
$scores = [60, 100];
$scores[] = 71; // or, use array_push()
// $scores = [60, 100, 71]
array_unshift($scores, 80);
// $scores = [80, 60, 100, 71]
$first = array_shift($scores);
// $first = 80, $scores = [60, 100, 71]
Array in PHP
• 也可以當hash table來用,超爽
  (dictionary in python)
$stu = [
      “name” => “ensky”,
      “height” => “180”,
      “weight” => “65”
];
echo $stu[“name”]; // ensky
Array in PHP
有超多好用的function可以使用
• array_rand – 從array中隨機挑一個元素出來
• array_slice – 切割陣列
• array_unique – 把陣列中重複的元素去掉
• shuffle – 把陣列隨機排序

還有好多排序function,穩定排序、照key排序、
照value排序等等等…..
• http://www.php.net/manual/en/ref.array.php
foreach in PHP
• PHP其他的流程控制都跟c++很像,在此不
  多提(for, while, do…while, switch, if, else …)。

• 介紹一個比較特別的operator                foreach

• 簡單來說,就是從一個陣列中,
  把東西一個一個依序拿出來
foreach in PHP
$scores = [60, 59, 58];
foreach ($scores as $score) {
    echo $score . “ ”;
}
// will output 60 59 58

但我想知道他是第幾個元素,怎麼辦哩?
foreach in PHP
$scores = [60, 59, 58];
foreach ($scores as $index => $score) {
    echo $index . “:” . $score . “ ”;
}
// will output 0:60 1:59 2:58
foreach in PHP
同理,可以適用在dictionary的情況下
$person = [
     “name” => “ensky”,
     “height” => 180
]
foreach ( $person as $key => $val ) {
    echo “{$key} => {$val}n”;
}
// name => ensky
// height => 180
include / require in PHP
在C++的時代,我們會把一份code拆成*.h檔和
*.cpp檔案,其中*.h每次compile都會一起
compile進去。
而*.cpp則是預先compile完畢,再用linker將他
們連結在一起。

Header file裡面只包含「定義」。
Source file裡面是程式碼本身。
include / require in PHP
而PHP呢,因為變數、class不需要先編譯才會
執行,因此我們就不需要拆成header file和
source file,直接全部include進來即可。

<?php
include “funcs.php”;
// OR
require “funcs.php”;
include / require in PHP
然而,有幾個issue要注意
1. PHP的include有分兩種,一種是include,
   另一種是require,差別在於,若該檔案找
   不到,include不會噴error,而require會。

  一般情況下,你不會期待include一個檔案,
  然後他找不到之後還繼續跑吧,所以我們
  一般情況下會用require。
include / require in PHP
2. 目錄問題:
   一般在include的時候,你很難確定到底你是
   從哪裡開始include的,比方說:
// index.php
<?php
require “func/func.php”;
// in func/func.php
require “haha.php”; // include func/haha.php


但此時你的路徑是index.php那層
不是func資料夾內,因此haha.php會找不到
include / require in PHP
__DIR__ 是個神奇常數(Magic constants)
他會指向檔案本身的目錄,例如說我的檔案
放在/var/www/data/func/func.php
那麼__DIR__的值就是/var/www/data/func


ref:
http://php.net/manual/en/language.constants.predefined.php
include / require in PHP
因此我可以將剛剛的code改寫成
<?php
require __DIR__ . “/haha.php”;

如此一來,即使是PATH是在index.php執行的,
也不會找不到檔案。
include / require in PHP
3. 重複定義問題
如果PHP先宣告了某個function,之後再宣告
一次,就會出現重複定義錯誤

而使用require的話也是一樣,如果已經
require過一個檔案,之後再require一次,則
會有重複定義問題。
include / require in PHP
此時,我們會用require_once來解決

<?php
require_once “funcs.php”;
// 第二次不會作用,PHP會自己判斷是否require過了
require_once “funcs.php”;


所以我其實最常用require_once。
Homework

• 到http://www.php.net/manual/en/langref.php
  自修完class之前我沒講的部份

• 到 http://www.php.net/manual/en/book.array.php
  去看看array有哪些function可以用
Homework
• 實作題 II:計算機
  算出postfix運算式的結果
  ex: 345*+67*+89*+1+ = 138
Requirement:
• 題目存在$str變數裡
• 答案直接echo出來
• 每個數字只有1位數
參考function:
• str_split
• is_numeric
• array_pop

More Related Content

What's hot (20)

DOC
部分PHP问题总结[转贴]
wensheng wei
 
PDF
深入淺出 Web 容器 - Tomcat 原始碼分析
Justin Lin
 
ODP
新北市教師工作坊 -- Bash script programming 介紹
fweng322
 
PDF
Ooredis
iammutex
 
ODP
Ruby程式語言入門導覽
Mu-Fan Teng
 
PDF
Erlang Practice
litaocheng
 
PDF
Patterns in Zend Framework
Jace Ju
 
PDF
OpenWebSchool - 03 - PHP Part II
Hung-yu Lin
 
PDF
Perl 6 news at 2010-06
March Liu
 
PDF
Introduction to Parse JavaScript SDK
維佋 唐
 
PDF
The Evolution of Async Programming (GZ TechParty C#)
jeffz
 
PPT
Perl在nginx里的应用
琛琳 饶
 
PPT
Php
pukongkong
 
PPT
Javascript Training
beijing.josh
 
PDF
Python 于 webgame 的应用
勇浩 赖
 
PDF
Phpconf 2011 introduction_to_codeigniter
Bo-Yi Wu
 
PDF
PHPUnit 入門介紹
Jace Ju
 
PDF
Bash入门基础篇
Zhiyao Pan
 
PPT
页游开发中的 Python 组件与模式
勇浩 赖
 
PDF
OpenEJB - 另一個選擇
Justin Lin
 
部分PHP问题总结[转贴]
wensheng wei
 
深入淺出 Web 容器 - Tomcat 原始碼分析
Justin Lin
 
新北市教師工作坊 -- Bash script programming 介紹
fweng322
 
Ooredis
iammutex
 
Ruby程式語言入門導覽
Mu-Fan Teng
 
Erlang Practice
litaocheng
 
Patterns in Zend Framework
Jace Ju
 
OpenWebSchool - 03 - PHP Part II
Hung-yu Lin
 
Perl 6 news at 2010-06
March Liu
 
Introduction to Parse JavaScript SDK
維佋 唐
 
The Evolution of Async Programming (GZ TechParty C#)
jeffz
 
Perl在nginx里的应用
琛琳 饶
 
Javascript Training
beijing.josh
 
Python 于 webgame 的应用
勇浩 赖
 
Phpconf 2011 introduction_to_codeigniter
Bo-Yi Wu
 
PHPUnit 入門介紹
Jace Ju
 
Bash入门基础篇
Zhiyao Pan
 
页游开发中的 Python 组件与模式
勇浩 赖
 
OpenEJB - 另一個選擇
Justin Lin
 

Similar to OpenWebSchool - 02 - PHP Part I (20)

PDF
PHP 語法基礎與物件導向
Shengyou Fan
 
PDF
[PHP 也有 Day #64] PHP 升級指南
Shengyou Fan
 
PDF
Migrations 與 Schema 操作
Shengyou Fan
 
PDF
iosdfoijehsogijlphpasjkdhiusghfripugsah;dfjkhs;kjfhi
1300672728
 
PDF
OpenWebSchool - 01 - WWW Intro
Hung-yu Lin
 
PDF
Learning python in the motion picture industry by will zhou
Will Zhou
 
PDF
Migrations 與 Schema操作
Shengyou Fan
 
PDF
[COSCUP 2022] 讓黑畫面再次偉大 - 用 PHP 寫 CLI 工具
Shengyou Fan
 
PPTX
JavaScript 80+ Programming and Optimization Skills
Ho Kim
 
PPT
Python 入门
kuco945
 
PPTX
第三方内容开发最佳实践
taobao.com
 
PPTX
DevOpsDays Taipei 2018 - Puppet 古早味、新感受:改造老牌企業進入自動化時代
scott liao
 
PDF
Schema & Migration操作
Shengyou Fan
 
DOCX
Puppet安装测试
Yiwei Ma
 
PDF
模块一-Go语言特性.pdf
czzz1
 
PPTX
[2]futurewad樹莓派研習會 141127
CAVEDU Education
 
PDF
Phalcon the fastest php framework 阿土伯
Hash Lin
 
PDF
Phalcon phpconftw2012
Rack Lin
 
PDF
[Modern Web 2016] 讓你的 PHP 開發流程再次潮起來
Shengyou Fan
 
PPTX
课题一:PHP5.3、PHP5.4的特性介绍与深度挖掘
Liu Allen
 
PHP 語法基礎與物件導向
Shengyou Fan
 
[PHP 也有 Day #64] PHP 升級指南
Shengyou Fan
 
Migrations 與 Schema 操作
Shengyou Fan
 
iosdfoijehsogijlphpasjkdhiusghfripugsah;dfjkhs;kjfhi
1300672728
 
OpenWebSchool - 01 - WWW Intro
Hung-yu Lin
 
Learning python in the motion picture industry by will zhou
Will Zhou
 
Migrations 與 Schema操作
Shengyou Fan
 
[COSCUP 2022] 讓黑畫面再次偉大 - 用 PHP 寫 CLI 工具
Shengyou Fan
 
JavaScript 80+ Programming and Optimization Skills
Ho Kim
 
Python 入门
kuco945
 
第三方内容开发最佳实践
taobao.com
 
DevOpsDays Taipei 2018 - Puppet 古早味、新感受:改造老牌企業進入自動化時代
scott liao
 
Schema & Migration操作
Shengyou Fan
 
Puppet安装测试
Yiwei Ma
 
模块一-Go语言特性.pdf
czzz1
 
[2]futurewad樹莓派研習會 141127
CAVEDU Education
 
Phalcon the fastest php framework 阿土伯
Hash Lin
 
Phalcon phpconftw2012
Rack Lin
 
[Modern Web 2016] 讓你的 PHP 開發流程再次潮起來
Shengyou Fan
 
课题一:PHP5.3、PHP5.4的特性介绍与深度挖掘
Liu Allen
 
Ad

More from Hung-yu Lin (9)

PDF
2014 database - course 2 - php
Hung-yu Lin
 
PDF
2014 database - course 3 - PHP and MySQL
Hung-yu Lin
 
PDF
2014 database - course 1 - www introduction
Hung-yu Lin
 
PDF
OpenWebSchool - 11 - CodeIgniter
Hung-yu Lin
 
PDF
OpenWebSchool - 06 - PHP + MySQL
Hung-yu Lin
 
PDF
OpenWebSchool - 05 - MySQL
Hung-yu Lin
 
PDF
Dremel: interactive analysis of web-scale datasets
Hung-yu Lin
 
PDF
Google App Engine
Hung-yu Lin
 
PDF
Redis
Hung-yu Lin
 
2014 database - course 2 - php
Hung-yu Lin
 
2014 database - course 3 - PHP and MySQL
Hung-yu Lin
 
2014 database - course 1 - www introduction
Hung-yu Lin
 
OpenWebSchool - 11 - CodeIgniter
Hung-yu Lin
 
OpenWebSchool - 06 - PHP + MySQL
Hung-yu Lin
 
OpenWebSchool - 05 - MySQL
Hung-yu Lin
 
Dremel: interactive analysis of web-scale datasets
Hung-yu Lin
 
Google App Engine
Hung-yu Lin
 
Ad

OpenWebSchool - 02 - PHP Part I

  • 1. PHP - part I Ensky / 林宏昱
  • 2. Client – Server Recall HTTP Request HTTP Response + BODY(HTML)
  • 3. Server Implement 1. 建立連線(socket),等client進來 2. Client進來 -> 分析HTTP Request, 找出URL、Host、Cookie等等資訊 3. 根據上述資訊開始產生所需資料 4. 將產出的資料丟回Client
  • 4. Server Implement 1. 建立連線(socket),等client進來 2. Client進來 -> 分析HTTP Request, 拆出來! 找出URL、Host、Cookie等等資訊 3. 根據上述資訊開始產生所需資料 4. 將產出的資料丟回Client
  • 5. Server Implement 1. 建立連線(socket),等client進來 2. Client進來 -> 分析HTTP Request, Web 找出URL、Host、Cookie等等資訊 Server 3. 根據上述資訊開始產生所需資料 CGI 4. 將產出的資料丟回Client
  • 6. Server Implement HTTP Request HTTP Web server stdin + env Response + BODY stdout CGI
  • 7. CGI Implement include <iostream> using namespace std; int main () { cout “<!doctype html>”; cout “<html>”; cout “ <head>”; ...以下略 }
  • 9. We Save Your Time!
  • 11. HELLO WORLD! <?php echo “hello world!”; ?> OR hello world!
  • 12. PHP is a programming language PHP是某個人用C寫CGI寫到快吐血, 憤而寫出的程式語言 既然是程式語言,所有C++、JAVA、 Python、…,他們能做到的事情,PHP基本上 都辦得到 你可以用它來寫Web server、BBS抓魚機器人、 Hadoop程式、NP作業…XD
  • 13. PHP is a Interpreted language No need to compile, PHP will compile then execute. 不用compile的意思是他會在「每次」request 進來的時候compile,無論你有沒有改過那個 檔案。 – 很慢 所以我們通常會安裝一些快取OP code的外掛
  • 14. PHP 的型態 • 基本型態如下 – Boolean ( True / False ) – Integer – Float – String (“abc” ‘cde’) • 複雜型態如下 – Array – Object
  • 15. PHP 是個寬鬆型態的語言 • 變數在使用前不需宣告他的型態 $a = “this is a string” • 變數會自動轉換型態 $a = “1”; //String $b = $a + 1; //Integer
  • 16. PHP 是個寬鬆型態的語言 • 自動轉型好規好,有他的問題在 var_dump(“” == 0); // bool(true) var_dump(“0” == 0); // bool(true) var_dump(“0” == “”); // bool(false) • 因此很多的時候我們會需要 「連型態一起判斷」的判斷式 === – var_dump(“” === 0); // bool(false) • 強制轉型的方法和c++一樣,在此不多提
  • 17. Variable Scope in PHP C++裡面的scope for ( int i = 1; i <= 5; i++ ) { do something… } cout << i << endl; //這裡會錯,他會說i在這個scope裡面
  • 18. Variable Scope in PHP PHP裡面的scope • in Global 最外面的變數都是global 變數 • In function 在function內的變數都是local變數,沒有內 層scope。
  • 19. Variable Scope in PHP 要取用global變數有兩種方法, 假設現在有$a, $b在global裡面 function I_want_to_use_global_var () { global $a; $a = ‘x’; $GLOBALS[‘b’] = ‘y’; }
  • 20. Operator in PHP • 大家都會的 +, -, *, /, %, ++, -- <, <=, >, >=, ==, ===, !=, !== &&, || 其中,&&也可以寫成AND, ||也可以寫成OR • 字串連接用「.」 “this is a “ . “string”
  • 21. Operator in PHP • 變數和字串的連接有幾種方式 $a = 123; $b = “this is a number: ” . $a; $b = “this is a number: {$a}”; • 我個人比較偏好前一種,因為可以放運算 式。
  • 22. String in PHP PHP中,字串可以用單引號或雙引號包起來, 但兩者在PHP中意義不同 • 單引號包起來的字串,寫什麼就是什麼 $a = 123; echo ‘ $a is 123n haha ’; // $a is 123n haha • 雙引號包起來的字串,會幫你轉換變數、換行符號 等等 echo “ $a is 123n haha ” // 123 is 123 // haha
  • 23. Function in PHP • PHP的function很直覺使用 function is_even ($n) { return $n % 2 == 0; } echo is_even(1); // 0 • PHP的function也可以是個值 $is_even = function ($n) { return $n % 2 == 0; } echo $is_even(2); // 1
  • 24. Function in PHP • PHP function 的參數可以有預設值 function print_something ($str=‘a’) { echo $str; } print_something(‘123’); // 123 print_something(); // a
  • 26. Array in PHP • 可以像你平常用的array $scores = [60, 59, 70]; print_r($scores); /* Array ( [0] => 60 [1] => 59 [2] => 70 ) */ echo $scores[1]; // 59
  • 27. Array in PHP • 可以當queue或stack來用,超爽 $scores = [60, 100]; $scores[] = 71; // or, use array_push() // $scores = [60, 100, 71] array_unshift($scores, 80); // $scores = [80, 60, 100, 71] $first = array_shift($scores); // $first = 80, $scores = [60, 100, 71]
  • 28. Array in PHP • 也可以當hash table來用,超爽 (dictionary in python) $stu = [ “name” => “ensky”, “height” => “180”, “weight” => “65” ]; echo $stu[“name”]; // ensky
  • 29. Array in PHP 有超多好用的function可以使用 • array_rand – 從array中隨機挑一個元素出來 • array_slice – 切割陣列 • array_unique – 把陣列中重複的元素去掉 • shuffle – 把陣列隨機排序 還有好多排序function,穩定排序、照key排序、 照value排序等等等….. • http://www.php.net/manual/en/ref.array.php
  • 30. foreach in PHP • PHP其他的流程控制都跟c++很像,在此不 多提(for, while, do…while, switch, if, else …)。 • 介紹一個比較特別的operator foreach • 簡單來說,就是從一個陣列中, 把東西一個一個依序拿出來
  • 31. foreach in PHP $scores = [60, 59, 58]; foreach ($scores as $score) { echo $score . “ ”; } // will output 60 59 58 但我想知道他是第幾個元素,怎麼辦哩?
  • 32. foreach in PHP $scores = [60, 59, 58]; foreach ($scores as $index => $score) { echo $index . “:” . $score . “ ”; } // will output 0:60 1:59 2:58
  • 33. foreach in PHP 同理,可以適用在dictionary的情況下 $person = [ “name” => “ensky”, “height” => 180 ] foreach ( $person as $key => $val ) { echo “{$key} => {$val}n”; } // name => ensky // height => 180
  • 34. include / require in PHP 在C++的時代,我們會把一份code拆成*.h檔和 *.cpp檔案,其中*.h每次compile都會一起 compile進去。 而*.cpp則是預先compile完畢,再用linker將他 們連結在一起。 Header file裡面只包含「定義」。 Source file裡面是程式碼本身。
  • 35. include / require in PHP 而PHP呢,因為變數、class不需要先編譯才會 執行,因此我們就不需要拆成header file和 source file,直接全部include進來即可。 <?php include “funcs.php”; // OR require “funcs.php”;
  • 36. include / require in PHP 然而,有幾個issue要注意 1. PHP的include有分兩種,一種是include, 另一種是require,差別在於,若該檔案找 不到,include不會噴error,而require會。 一般情況下,你不會期待include一個檔案, 然後他找不到之後還繼續跑吧,所以我們 一般情況下會用require。
  • 37. include / require in PHP 2. 目錄問題: 一般在include的時候,你很難確定到底你是 從哪裡開始include的,比方說: // index.php <?php require “func/func.php”; // in func/func.php require “haha.php”; // include func/haha.php 但此時你的路徑是index.php那層 不是func資料夾內,因此haha.php會找不到
  • 38. include / require in PHP __DIR__ 是個神奇常數(Magic constants) 他會指向檔案本身的目錄,例如說我的檔案 放在/var/www/data/func/func.php 那麼__DIR__的值就是/var/www/data/func ref: http://php.net/manual/en/language.constants.predefined.php
  • 39. include / require in PHP 因此我可以將剛剛的code改寫成 <?php require __DIR__ . “/haha.php”; 如此一來,即使是PATH是在index.php執行的, 也不會找不到檔案。
  • 40. include / require in PHP 3. 重複定義問題 如果PHP先宣告了某個function,之後再宣告 一次,就會出現重複定義錯誤 而使用require的話也是一樣,如果已經 require過一個檔案,之後再require一次,則 會有重複定義問題。
  • 41. include / require in PHP 此時,我們會用require_once來解決 <?php require_once “funcs.php”; // 第二次不會作用,PHP會自己判斷是否require過了 require_once “funcs.php”; 所以我其實最常用require_once。
  • 42. Homework • 到http://www.php.net/manual/en/langref.php 自修完class之前我沒講的部份 • 到 http://www.php.net/manual/en/book.array.php 去看看array有哪些function可以用
  • 43. Homework • 實作題 II:計算機 算出postfix運算式的結果 ex: 345*+67*+89*+1+ = 138 Requirement: • 題目存在$str變數裡 • 答案直接echo出來 • 每個數字只有1位數 參考function: • str_split • is_numeric • array_pop