Re: [請益] echo

看板PHP作者 ( )時間15年前 (2010/08/07 00:21), 編輯推噓2(207)
留言9則, 4人參與, 最新討論串2/2 (看更多)
※ 引述《serveto ( )》之銘言: : 標題: [請益] echo : 時間: Fri Aug 6 23:29:31 2010 : : 為何有些函數呼叫要用echo : 有些不需要? : : -- : ※ 發信站: 批踢踢實業坊(ptt.cc) : ◆ From: 114.44.149.22 : → kosjason:可以說的詳細點嗎 可以舉例嗎 這樣很難答= = 08/07 00:07 http://www.emanueleferonato.com/2008/12/09/sudoku-creatorsolver-with-php/ 在這個連結裡的print_sudoku函數 "...... function print_sudoku($sudoku){ $html = "<table bgcolor = \"#000000\" cellspacing = \"1\" cellpadding = \"2\">"; for($x=0;$x<=8;$x++){ $html .= "<tr bgcolor = \"white\" align = \"center\">"; for($y=0;$y<=8;$y++){ $html.= "<td width = \"20\" height = \"20\">".$sudoku[$x*9+$y]."</td>"; } $html .= "</tr>"; } $html .= "</table>"; return $html; } ... " 我自己用記事本測試: " <?php function print_sudoku($sudoku){ $html = "<table bgcolor = \"#000000\" cellspacing = \"1\" cellpadding = \"2\">"; for($x=0;$x<=8;$x++){ $html .= "<tr bgcolor = \"white\" align = \"center\">"; for($y=0;$y<=8;$y++){ $html.= "<td width = \"20\" height = \"20\">".$sudoku[$x*9+$y]."</td>"; } $html .= "</tr>"; } $html .= "</table>"; return $html; } echo print_sudoku($sudoku); ?> " 結果有出來9*9方格。而在沒有echo情形下直接print_sudoku()是空白 -- 但是最後一個函數solve($sudoku)卻可以直接呼叫?(看網頁裡程式碼最後。) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.44.150.92 ※ 編輯: serveto 來自: 114.44.150.92 (08/07 00:21)

08/07 00:33, , 1F
因為solve()最後做了echo的動作啊
08/07 00:33, 1F

08/07 00:33, , 2F
print_sudoku() 只是做 return 的動作而已
08/07 00:33, 2F

08/07 00:37, , 3F
有回傳和有echo 是2回事...xd
08/07 00:37, 3F

08/07 00:38, , 4F
不是function name 有個print就會印出來...XD
08/07 00:38, 4F
※ 編輯: serveto 來自: 114.44.150.92 (08/07 00:53)

08/07 00:58, , 5F
那為何我在print_sudoku函式最後加個echo $html;
08/07 00:58, 5F

08/07 00:58, , 6F
還是不能直接呼叫?
08/07 00:58, 6F

08/07 01:26, , 7F
你是在return $html後面加echo $html嗎?
08/07 01:26, 7F

08/07 01:26, , 8F
如果是的話 已經return了 剩餘的部分就不會再執行囉@.@
08/07 01:26, 8F

08/07 02:06, , 9F
謝謝喔:)
08/07 02:06, 9F
文章代碼(AID): #1CN3QISo (PHP)
討論串 (同標題文章)
本文引述了以下文章的的內容:
0
2
15年前, 08/06
完整討論串 (本文為第 2 之 2 篇):
2
9
0
2
15年前, 08/06
文章代碼(AID): #1CN3QISo (PHP)