作者serveto ( )
看板PHP
標題Re: [請益] echo
時間Sat Aug 7 00:21:35 2010
※ 引述《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)
1F:推 bigair:因為solve()最後做了echo的動作啊 08/07 00:33
2F:→ bigair:print_sudoku() 只是做 return 的動作而已 08/07 00:33
3F:→ sjrom:有回傳和有echo 是2回事...xd 08/07 00:37
4F:→ sjrom:不是function name 有個print就會印出來...XD 08/07 00:38
※ 編輯: serveto 來自: 114.44.150.92 (08/07 00:53)
5F:→ serveto:那為何我在print_sudoku函式最後加個echo $html; 08/07 00:58
6F:→ serveto:還是不能直接呼叫? 08/07 00:58
7F:推 etetet91:你是在return $html後面加echo $html嗎? 08/07 01:26
8F:→ etetet91:如果是的話 已經return了 剩餘的部分就不會再執行囉@.@ 08/07 01:26
9F:→ serveto:謝謝喔:) 08/07 02:06