- 相關(guān)推薦
php的checkbox取值詳細說明
php的checkbox取值方式跟其它語言有點不同,主要是因為php中數(shù)組的合理使用,希望對大家有所幫助!
設(shè)我們有一個html頁面,代碼如下:
復制代碼 代碼如下:
<FORM method="post" action="checkTest.php">
<INPUT name="test[]" type="checkbox" value="1" />
<INPUT type="checkbox" name="test[]" value="2" />
<INPUT type="checkbox" name="test[]" value="3" />
<INPUT type="checkbox" name="test[]" value="4" />
<INPUT type="checkbox" name="test[]" value="5" />
<INPUT type="submit" name="Submit" value="Submit" />
</FORM>
注意上面input的name屬性,各個屬性內(nèi)容都一樣,而且都是test[],加上[]的原因在于讓test的內(nèi)容變成數(shù)組形式傳遞。
checkTest.php的代碼內(nèi)容如下:
復制代碼 代碼如下:
<?php
echo implode(",",$_POST['test']);
?>
我們輸出內(nèi)容時只需要注意利用implode函數(shù)將數(shù)組內(nèi)容轉(zhuǎn)化為字符串即可。
注:該功能可在刪除多記錄等場合運用。如Delete from tbl where ID in (implode(",",$_POST['test']))即可。
實例代碼:
復制代碼 代碼如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
</head>
<body>
html復選框如果要以數(shù)據(jù)組形式發(fā)送給php腳本處理就必須以如checkbox[]這形式
<form id="form1" name="form1" method="post" action="">
<label>
<input type="checkbox" name="checkbox[]" value="1" />
</label>
<label>
<input type="checkbox" name="checkbox[]" value="2" />
</label>
<label>
<input type="checkbox" name="checkbox[]" value="www.jb51.net" />
</label>
<label>
<input type="checkbox" name="checkbox[]" value="jb51.net" />
</label>
<label>
<input type="submit" name="Submit" value="提交" />
</label>
</form>
</body>
</html>
<?
//判斷是否點擊提交
if( $_POST )
{
$array = $_POST['checkbox'];
print_r($array);
}
/*
結(jié)果:
Array
(
[0] => 1
[1] => 2
[2] => www.jb51.net
[3] => jb51.net
)
簡單的很多事情在做之前覺得復雜但做起來就很容易了,像這個復選框代碼就是這樣了。
*/
?>
【php的checkbox取值詳細說明】相關(guān)文章:
php框架Phpbean說明09-30
php生成靜態(tài)頁面的詳細教程10-15
php5.3注意事項說明06-16
PHP常用編譯參數(shù)中文說明09-28
2016年北京中考說明詳細解讀08-17
GMAT考試內(nèi)容詳細說明08-26
職稱日語考試報名流程詳細說明07-30
2015中考考試說明詳細解讀11-05
2016年雅思報名流程詳細說明09-20