<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>網頁設計,網路行銷新知&#187; BUSINESSWING &#8211; 整合提供網頁設計,網站企劃,網路行銷等新知</title>
	<atom:link href="http://businesswing.net/tag/web-design/feed/" rel="self" type="application/rss+xml" />
	<link>http://businesswing.net</link>
	<description>提供的不只是網頁設計,網頁製作,網頁企劃,更重視網頁優化(SEO)及網頁行銷概念的注入</description>
	<lastBuildDate>Fri, 20 Aug 2010 09:25:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>5-7   中斷指令</title>
		<link>http://businesswing.net/webdesign/interrupt-instruction/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=interrupt-instruction</link>
		<comments>http://businesswing.net/webdesign/interrupt-instruction/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 09:25:58 +0000</pubDate>
		<dc:creator>bwingnet</dc:creator>
				<category><![CDATA[網頁程式PHP]]></category>
		<category><![CDATA[網頁設計]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://businesswing.net/?p=1549</guid>
		<description><![CDATA[理論上，我們設計好迴圈，就已經先評估過迴圈會跑多少次，或者在不符合條件下自然跳出。但是，在迴圈進行的過程中，我們希望迴圈能做各種不同的中斷或退出，那該怎麼做呢？PHP提供了三種中斷指令：break、continue與exit，我們可由這三個指令瞭解如何中斷迴圈或特定語法的執行。
5-7-1  break
break這個指令在前面介紹switch case時有出現過，這裡又再出現一次，break這個指令會對迴圈產生什麼影響呢？

&#60;html&#62;&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34;&#62;
&#60;title&#62;break &#60;/title&#62;&#60;/head&#62;
&#60;body&#62;&#60;?
for ($i=1;$i&#60;=10;$i++)
{  if ($i==5)
{
     echo &#34;迴圈停止&#60;br&#62;&#34;;
     break;
}
echo &#34;i-&#62;&#34;.$i.&#34;&#60;br&#62;&#34;;
echo &#34;before a-&#62;&#34;.$a.&#34;&#60;br&#62;&#34;;
$a += $i;
echo &#34;after a-&#62;&#34;.$a.&#34;&#60;br&#62;&#34;;
echo &#34;&#60;hr&#62;&#34;;
}
echo &#34;總和是&#34;.$a;
?&#62;&#60;/body&#62;&#60;/html&#62;

【圖25  迴圈中斷：執行break】
這是一個迴圈，由1加到10的for迴圈，但是在迴圈內有一個if條件判斷式，也就是06行到10行：


06：
	{  if ($i==5)
07：
	{
08：
     	     echo &#8220;迴圈停止&#60;br&#62;&#8221;;
09：
     	   [...]]]></description>
		<wfw:commentRss>http://businesswing.net/webdesign/interrupt-instruction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5-6-2  do  while迴圈</title>
		<link>http://businesswing.net/webdesign/do-while-loop/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=do-while-loop</link>
		<comments>http://businesswing.net/webdesign/do-while-loop/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 09:16:26 +0000</pubDate>
		<dc:creator>bwingnet</dc:creator>
				<category><![CDATA[網頁程式PHP]]></category>
		<category><![CDATA[網頁設計]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://businesswing.net/?p=1546</guid>
		<description><![CDATA[do while迴圈與while迴圈非常相似，我們來看do while迴圈的格式：

	

do{
  //執行的迴圈語法
} while (條件判斷);

	

請您注意，do while迴圈的while()這一行有加上分號「;」。
while迴圈是「先判斷再執行迴圈內的語法」，而do while迴圈則是「先執行迴圈內的語法再做判斷」。我們來看看以下的範例，我們想要寫一個1加到某數的總和，當條件成立與不成立時，迴圈各有什麼變化，首先我們來看當條件成立時：


&#60;html&#62;&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34;&#62;
&#60;title&#62;dowhile：當條件成立時 &#60;/title&#62;&#60;/head&#62;
&#60;body&#62;&#60;?
$i = 1;
$a= 0;
do {   
    $a +=$i;
    $i++;
	  echo &#34;i=&#34;.$i.&#34;&#60;br&#62;&#34;;
	  echo &#34;a=&#34;.$a.&#34;&#60;br&#62;&#34;;
echo &#34;&#60;hr&#62;&#34;;
}while ($i&#60;10);
?&#62; &#60;/body&#62;&#60;/html&#62;

【圖23  條件成立下執行do while迴圈】
do while迴圈的條件判斷式在13行：


13：
	}while ($i&#60;10);


先執行迴圈內的語法，再判斷「$i小於10」的條件是否成立，若成立就繼續執行迴圈。
而一開始$i的值為1，第一次執行完網頁的09行「$i++;」後$i的內容成為2，仍符合「$i小於10」的條件，所以迴圈就繼續執行，直到「$i小於10」的條件不成立時。
接者，我們來看看若條件不符合時，dowhile迴圈會如何執行？

&#60;html&#62;&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34;&#62;
&#60;title&#62;dowhile：當條件不成立時 &#60;/title&#62;&#60;/head&#62;
&#60;body&#62;&#60;?
$i = 11;
$a= 0;
do{  
    [...]]]></description>
		<wfw:commentRss>http://businesswing.net/webdesign/do-while-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5-6  while與do while</title>
		<link>http://businesswing.net/webdesign/while_and_do-while/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=while_and_do-while</link>
		<comments>http://businesswing.net/webdesign/while_and_do-while/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 10:23:19 +0000</pubDate>
		<dc:creator>bwingnet</dc:creator>
				<category><![CDATA[網頁程式PHP]]></category>
		<category><![CDATA[網頁設計]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://businesswing.net/?p=1543</guid>
		<description><![CDATA[for迴圈因為有「固定的範圍」與「固定的變化」這兩個限制，所以for迴圈適合固定數量的迴圈運用，假如我的資料沒有固定數量或沒有固定變化呢？這時我們可以使用while或do while迴圈來設計。
5-6-1  while迴圈
我們來看while迴圈的格式：

	
while (條件判斷){
//條件成立時會執行的迴圈語法
}
	


我們來看看以下的範例，我們想要寫一個1加到某數的總和，當條件成立與不成立時，迴圈各有什麼變化，首先我們來看當條件成立時：

&#60;html&#62;&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34;&#62;
&#60;title&#62;while：當條件成立時 &#60;/title&#62;&#60;/head&#62;
&#60;body&#62;&#60;?
$i = 1;
$a= 0;
while ($i&#60;10){  
    $a +=$i;
    $i++;
	  echo &#34;i=&#34;.$i.&#34;&#60;br&#62;&#34;;
	  echo &#34;a=&#34;.$a.&#34;&#60;br&#62;&#34;;
echo &#34;&#60;hr&#62;&#34;;
}
?&#62; &#60;/body&#62;&#60;/html&#62;

【圖21  條件成立下執行while迴圈】
while迴圈的條件判斷式在07行：


07：
	while ($i&#60;10){


代表當$i小於10的情況下，都可以執行大括弧內的迴圈程式。
而一開始$i的值為1，所以迴圈就可以執行。當條件成立時，迴圈要跑哪些語法呢？


08：
$a +=$i;
09：
$i++;
10：
echo &#8220;i=&#8221;.$i.&#8221;&#60;br&#62;&#8221;;
11：
echo &#8220;a=&#8221;.$a.&#8221;&#60;br&#62;&#8221;;
12：
echo &#8220;&#60;hr&#62;&#8221;;


08行代表 $a=$a+$i，而09行代表執行完這一行$i的值會加1。10行到12行則都是輸出。
  接者，我們來看看若條件不符合時，while迴圈會如何執行？

&#60;html&#62;&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34;&#62;
&#60;title&#62;while：當條件不成立時 &#60;/title&#62;&#60;/head&#62;
&#60;body&#62;&#60;?
$i = 11;
$a= 0;
while ($i&#60;10){  
    [...]]]></description>
		<wfw:commentRss>http://businesswing.net/webdesign/while_and_do-while/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5-5-3  for迴圈設計的風險</title>
		<link>http://businesswing.net/webdesign/risk-of-loop/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=risk-of-loop</link>
		<comments>http://businesswing.net/webdesign/risk-of-loop/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 10:10:50 +0000</pubDate>
		<dc:creator>bwingnet</dc:creator>
				<category><![CDATA[網頁程式PHP]]></category>
		<category><![CDATA[網頁設計]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://businesswing.net/?p=1535</guid>
		<description><![CDATA[for迴圈有三個條件，如果這三個條件彼此間無法搭配，會造成迴圈無法執行或成為無限迴圈。我們可使用以下的例子說明，for迴圈執行時會有哪些變化：

&#60;html&#62;&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34;&#62;
&#60;title&#62;forerror1：for迴圈的風險 &#60;/title&#62;&#60;/head&#62;
&#60;body&#62;&#60;?
$a=0;	
for ($i=1;$i!=10;$i+=2) 
{    echo &#34;i-&#62;&#34;.$i.&#34;&#60;br&#62;&#34;;      
     echo &#34;before a-&#62;&#34;.$a.&#34;&#60;br&#62;&#34;;
     $a += $i;
     echo &#34;after a-&#62;&#34;.$a.&#34;&#60;br&#62;&#34;;
     echo &#34;&#60;hr&#62;&#34;;
}
echo $a;
?&#62;&#60;/body&#62;&#60;/html&#62;

【圖19  迴圈設計不當造成無限迴圈，這是執行一段時間後的畫面】
請您看06行語法：


06：
	for ($i=1;$i!=10;$i+=2)


乍看之下，與前一個for0.php檔案相似，但是我們把這三個條件列表做說明：


	$i=1;
	$i的初始值為1
$i!=10;當$i不等於10的情況下
$i++每跑完一次迴圈$i就加1


我們可以來跑跑看迴圈會怎麼跑


1
	當$i=1時
	$a+=$i，原本$a=0，$i=1，所以$a=1
	$i+=2，所以$i=3
2
	當$i=3時
	$a+=$i，原本$a=1，$i=3，所以$a=4
	$i+=2，所以$i=5
3
	當$i=5時
	$a+=$i，原本$a=4，$i=5，所以$a=9
	$i+=2，所以$i=7
4
	當$i=7時
	$a+=$i，原本$a=9，$i=7，所以$a=16
	$i+=2，所以$i=9
5
	當$i=9時
	$a+=$i，原本$a=16，$i=9，所以$a=25
	$i+=2，所以$i=11
6
	當$i=11時
	$a+=$i，原本$a=25，$i=11，所以$a=36
	$i+=2，所以$i=13


您會發現到$i永遠不等於10，換句話說，永遠符合條件，所以迴圈會不斷的跑。
那以下的條件，請思考是否可以執行？：

&#60;html&#62;&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34;&#62;
&#60;title&#62;forerror2：for迴圈的風險 &#60;/title&#62;&#60;/head&#62;
&#60;body&#62;&#60;?
$a=0;	
for ($i=11;$i&#38;lt;=10;$i++)  [...]]]></description>
		<wfw:commentRss>http://businesswing.net/webdesign/risk-of-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5-5-2-巢狀迴圈</title>
		<link>http://businesswing.net/webdesign/nested-loop/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=nested-loop</link>
		<comments>http://businesswing.net/webdesign/nested-loop/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 09:56:01 +0000</pubDate>
		<dc:creator>bwingnet</dc:creator>
				<category><![CDATA[網頁程式PHP]]></category>
		<category><![CDATA[網頁設計]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://businesswing.net/webdesign/5-5-2-%e5%b7%a2%e7%8b%80%e8%bf%b4%e5%9c%88/</guid>
		<description><![CDATA[有時我們需要的條件，可能是很多個for迴圈兜在一起，彼此之間都有關係，例如九九乘法表，您會發現什麼？
您會發現到迴圈的變化有兩圈，一圈在外面，一圈在裡面。外面那一圈會等裡面的跑完，才會跑下一個資料。我們可以這樣想，就像單車上面的相依的大小齒輪，小齒輪跑完一圈後，再由大齒輪進一格。這裡舉一個簡單的例子，由此例子瞭解巢狀迴圈執行的流程：

&#60;html&#62;&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34;&#62;
&#60;title&#62;巢狀迴圈介紹 &#60;/title&#62;&#60;/head&#62;
&#60;body&#62;&#60;?
for ($a=1;$a&#60;=3;$a++) 
{    
  for ($b=1;$b&#60;=3;$b++) 
  { 
   echo &#34;a-&#62;&#34;.$a.&#34;&#60;br&#62;&#34;;
   echo &#34;b-&#62;&#34;.$b.&#34;&#60;hr&#62;&#34;;
}
}   
?&#62;&#60;/body&#62;&#60;/html&#62;

【圖18  巢狀迴圈】
您可看到這個練習，$a在1的時候，$b由1跑到3跑完後，$a再加1，而$b由1跑到3跑完後，$a再加1。
巢狀for迴圈語法的基本架構為：

	
		
for() //外層的迴圈
｛
for() // 內層的迴圈
 {
重覆執行的語法
 ｝
}
	

葉建榮 jiannrong@gmail.com         ]]></description>
		<wfw:commentRss>http://businesswing.net/webdesign/nested-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5-5  for迴圈</title>
		<link>http://businesswing.net/webdesign/for-loop/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=for-loop</link>
		<comments>http://businesswing.net/webdesign/for-loop/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 10:14:20 +0000</pubDate>
		<dc:creator>bwingnet</dc:creator>
				<category><![CDATA[網頁程式PHP]]></category>
		<category><![CDATA[網頁設計]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://businesswing.net/?p=1529</guid>
		<description><![CDATA[我們可以請PHP網頁協助我們做條件判斷，也可以請PHP網頁協助我們執行重複的工作，例如我們設計一個網頁，想要知道1到100有哪幾個偶數，該怎麼計算？要一個一個加嗎？如果改成表單，我們想要知道1到N有哪幾個偶數，該怎麼計算？N是表單輸入的值，那該怎麼做呢？這裡我們就得使用迴圈，協助我們完成。
for迴圈需要三個條件，這三個條件均成立的情況下迴圈才會執行，所以是條件較為嚴謹且複雜的迴圈型式。
 for迴圈語法的基本架構為：

	
		for(變數初始值；變數的判斷式；每執行一次迴圈後變數的變化)｛//重覆執行的語法｝
	

5-5-1  for迴圈的變化
我們可使用以下的例子說明，for迴圈執行時會有哪些變化：

&#60;html&#62;&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34;&#62;
&#60;title&#62;迴圈介紹：for0 &#60;/title&#62;&#60;/head&#62;
&#60;body&#62;&#60;?
$a=0;	
for ($i=1;$i&#60;=10;$i++)
{    echo &#34;i-&#62;&#34;.$i.&#34;&#60;br&#62;&#34;;      
     echo &#34;before a-&#62;&#34;.$a.&#34;&#60;br&#62;&#34;;
     $a += $i;
     echo &#34;after a-&#62;&#34;.$a.&#34;&#60;br&#62;&#34;;
     echo &#34;&#60;hr&#62;&#34;;
}
echo $a;
?&#62;&#60;/body&#62;&#60;/html&#62;

【圖17  for迴圈】
請您看06行語法：


06：
	for ($i=1;$i< =10;$i++)


for()裡面有三個條件，分別是：


	$i=1;
	$i的初始值為1
$i< =10;當$i小於等於10的情況下
$i++每跑完一次迴圈$i就加1


因為一開始$i的值為1，符合「$i< =10;」的條件，所以就會進入迴圈，而每跑完一次迴圈，$i的值就會加1，再判斷是否符合「$i]]></description>
		<wfw:commentRss>http://businesswing.net/webdesign/for-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5-4 條件判斷式用於表單網頁的接收</title>
		<link>http://businesswing.net/webdesign/conditional-on-form/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=conditional-on-form</link>
		<comments>http://businesswing.net/webdesign/conditional-on-form/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 10:03:34 +0000</pubDate>
		<dc:creator>bwingnet</dc:creator>
				<category><![CDATA[網頁程式PHP]]></category>
		<category><![CDATA[網頁設計]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://businesswing.net/?p=1525</guid>
		<description><![CDATA[當表單將資料送出後，PHP接收資料時，我們就可依照前面介紹的條件判斷式語法，在接收資料時進行分析。例如我將第四章討論過的核選框表單網頁4.htm另存新檔為4new.htm，並將「action=&#8221;4.php&#8221;」改為「action=&#8221;4new.php&#8221;」，或請參考檔案名稱：「5」資料夾內「4new.htm」，接收網頁可以如此設計：

&#60;html&#62;&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34;&#62;
&#60;title&#62;用過哪些作業系統的接收1:加上條件判斷&#60;/title&#62;&#60;/head&#62;
&#60;body&#62;
&#60;? if($_GET['vista'] or $_GET['xp'] or $_GET['win2k'])
   {  
$win.=$_GET['vista'].&#34;/&#34;;
      $win.=$_GET['xp'].&#34;/&#34;
$win.=$_GET['win2k'].&#34;/&#34;;
echo &#8216;您挑選了以下的Windows系統：&#8217;.$win.&#34;&#60;hr&#62;&#34;;
    }
if($_GET['fedora'] or $_GET['opensuse'] or $_GET['ubuntu'])
{ 
$linux.=$_GET['fedora'].&#34;/&#34;;
$linux.=$_GET['opensuse'].&#34;/&#34;;
$linux.=$_GET['ubuntu'].&#34;/&#34;;
echo &#8216;您挑選了以下的Linux系統：&#8217;.$linux.&#34;&#60;hr&#62;&#34;;
} 	?&#62; &#60;/body&#62;&#60;/html&#62;

【圖15  接收表單網頁與條件判斷】

您會發現什麼呢？因為條件判斷式裡使用「or」邏輯判斷，所以只要windows系列的作業系統有一個項目勾選，就會執行06到11行的程式、而Linux系列的作業系統裡有一個項目勾選，也會執行13到17行的程式。
可是如果您沒有全部勾選，您會發現到螢幕上出現很多的「/」，這是為什麼呢？因為我們並沒有「判斷這個陣列變數是否存在」。那要如何「判斷這個陣列變數是否存在」？要我們自己寫「判斷這個陣列變數是否存在」的語法嗎？其實不用，PHP就有提供這樣的函數isset()可協助我們處理，函數是什麼？每一個函數內有多行語法，當我們使用或將資料丟入函數內，函數就會協助我們做資料處理，您就不用自己寫很多語法作分析。
例如我將第四章討論過的核選框表單網頁4.htm另存新檔為4new2.htm，並將「action=&#8221;4.php&#8221;」改為「action=&#8221;4new2.php&#8221;」，或請參考檔案名稱：「5」資料夾內「4new2.htm」，接收網頁可以如此設計：

&#60;html&#62;&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34;&#62;
&#60;title&#62;用過哪些作業系統的接收1:加上條件判斷與函數&#60;/title&#62;&#60;/head&#62;
&#60;body&#62;
&#60;? if($_GET['vista'] or $_GET['xp'] or $_GET['win2k'])
{
  if(isset($_GET['vista']))
  $win.=$_GET['vista'].&#34;/&#34;;
  if(isset($_GET['xp']))
  $win.=$_GET['xp'].&#34;/&#34;;
  if(isset($_GET['win2k']))
  $win.=$_GET['win2k'].&#34;/&#34;;
echo [...]]]></description>
		<wfw:commentRss>http://businesswing.net/webdesign/conditional-on-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5-3-2 邏輯運算子</title>
		<link>http://businesswing.net/webdesign/logical-operator/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=logical-operator</link>
		<comments>http://businesswing.net/webdesign/logical-operator/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 10:08:08 +0000</pubDate>
		<dc:creator>bwingnet</dc:creator>
				<category><![CDATA[網頁程式PHP]]></category>
		<category><![CDATA[網頁設計]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://businesswing.net/?p=1523</guid>
		<description><![CDATA[邏輯運算子主要用if或elseif內，當條件本身是否為真或假，會影響到判斷時，我們可藉由邏輯運算子協助取得資訊。
首先，我們先來看PHP有哪些邏輯運算子可以運用：








符號
範例
說明




	and
	$a and $b
	如果$a與$b都為真，那就會傳回真，否則傳回假


	or
	$a or $b
	如果$a與$b其中一個為真，那就會傳回真，否則傳回假


	xor
	$a xor $b
	如果$a與$b若均為真或為假，那就會傳回假，否則傳回真


	!
	!$a
	若$a為真，則會傳回假，若$a為假，則會傳回真



首先我們以範例說明and的用法：

&#60;html&#62;&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34;&#62;
&#60;title&#62;邏輯運算子判斷and&#60;/title&#62;&#60;/head&#62;
&#60;body&#62;&#60;?
$a=50;
$b=20;
 if (($a&#62;=50) and ($b&#60;=20)) 
   echo &#8216;($a&#62;=50) and ($b&#60;=20)邏輯運算子成立&#8217;.'&#60;br&#62;&#8217;;
 else 
  echo &#8216;($a&#62;=50) and ($b&#60;=20)邏輯運算子不成立&#8217;.'&#60;br&#62;&#8217;;
 if (($a&#60;50) and ($b&#62;20)) 
  echo &#8216;($a&#60;50) and ($b&#62;20)邏輯運算子成立&#8217;.'&#60;br&#62;&#8217;;
 else 
  echo &#8216;($a&#60;50) and ($b&#62;20)邏輯運算子不成立&#8217;.'&#60;br&#62;&#8217;;
 if (($a&#60;50) and ($b&#60;=20)) 
   echo &#8216;($a&#60;50) and [...]]]></description>
		<wfw:commentRss>http://businesswing.net/webdesign/logical-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5-3 條件判斷式中的運算子</title>
		<link>http://businesswing.net/webdesign/conditional-operator/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=conditional-operator</link>
		<comments>http://businesswing.net/webdesign/conditional-operator/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 09:02:52 +0000</pubDate>
		<dc:creator>bwingnet</dc:creator>
				<category><![CDATA[網頁程式PHP]]></category>
		<category><![CDATA[網頁設計]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://businesswing.net/?p=1520</guid>
		<description><![CDATA[比較運算子與邏輯運算子是用於條件判斷式中的運算子，我們來瞧瞧這兩種運算子與條件判斷式關係。
5-3-1 比較運算子
前面的範例中，當我們在進行條件判斷時，曾用過>與==兩種，我們在進行條件判斷時，有哪些比較運算子可以運用呢？
PHP有以下的比較運算子可以運用：








符號
意義
說明




	==
	相等
	兩個=


	!=
	不等
	文字的不相等


	&#60;&#62;
	不等
	數字上的不相等


	&#62;=
	大於等於
	&#160;


	&#60;=
	小於等於
	&#160;


	&#60;
	&#60;	小於
	&#160;



葉建榮 jiannrong@gmail.com         ]]></description>
		<wfw:commentRss>http://businesswing.net/webdesign/conditional-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5-2  switch case條件判斷式</title>
		<link>http://businesswing.net/webdesign/switch-case/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=switch-case</link>
		<comments>http://businesswing.net/webdesign/switch-case/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 08:51:43 +0000</pubDate>
		<dc:creator>bwingnet</dc:creator>
				<category><![CDATA[網頁程式PHP]]></category>
		<category><![CDATA[網頁設計]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://businesswing.net/?p=1518</guid>
		<description><![CDATA[因為傳送的資料固定就是這幾個，所以我們可以用swtich case方式來設計條件判斷式：

	
		switch （變數）{case 變數內容1:當這個條件成立時會執行的語法case 變數內容2:當這個條件成立時會執行的語法default:當上面列的case均不成立時會執行這個區塊內的語法}
	

請各位將表單網頁blood0.htm另存新檔為blood1.htm，並將「action=&#8221;blood0.php&#8221;」改為「action=&#8221;blood1.php&#8221;」，或請參考檔案名稱：「5」資料夾內「blood1.htm」，接收網頁可以如此設計，並請於blood1.htm選擇AB這個按鈕後送出查詢後觀察結果：

&#60;html&#62;&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34;&#62;
&#60;title&#62;接收血型&#60;/title&#62;&#60;/head&#62;&#60;body&#62;
&#60;?
$blood1=$_GET[&#34;blood&#34;];
switch ($blood1)
{  
case &#34;A&#34; :
echo &#34;您是A型&#34;;
    break;
case &#34;B&#34; :
echo &#34;您是B型&#34;;
break;
case &#34;AB&#34; :
echo &#34;您是AB型&#34;;
break;
case &#34;O&#34; :
echo &#34;您是O型&#34;;
break;
 }?&#62;&#60;/body&#62;&#60;/html&#62;      

因此，當各位於blood1.htm選擇AB這個按鈕後送出查詢，blood1.php網頁會依據您送來的資料，找到AB這個case（14行）來執行裡面的敘述。
這邊各位會發現有一個指令：break，這是什麼指令呢？假設我把所有的break加上註解，並且在blood1.htm選擇AB這個按鈕後送出查詢：（檔案名稱：

&#60;html&#62;&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34;&#62;
&#60;title&#62;接收血型&#60;/title&#62;&#60;/head&#62;&#60;body&#62;
&#60;?
$blood1=$_GET[&#34;blood&#34;];
switch ($blood1)
{  
case &#34;A&#34; :
echo &#34;您是A型&#34;;
    //break;
case &#34;B&#34; :
echo &#34;您是B型&#34;;
//break;
case &#34;AB&#34; :
echo &#34;您是AB型&#34;;
//break;
case &#34;O&#34; :
echo [...]]]></description>
		<wfw:commentRss>http://businesswing.net/webdesign/switch-case/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
