|
|
|
ทำการ count input เฉพาะ input ที่มีการกรอกข้อมูลครับ |
|
|
|
|
|
|
|
Code (PHP)
count(array_filter($_POST["to_more"]));
|
|
|
|
|
Date :
2014-01-30 14:29:33 |
By :
itpcc |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
if(isset($_POST["submit"]))
{
$c = 0;
foreach($_POST["to_more"] as $single)
if(!empty($single) || $single !== "") ++$c;
echo $c;
}
?>
<form name="f1" method="post">
<input type="text" name="to_more[]">
<input type="text" name="to_more[]">
<input type="text" name="to_more[]">
<input type="submit" name="submit" value="OK">
</form>
|
|
|
|
|
Date :
2014-01-30 14:51:33 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
function notempty($val){
return !empty($val);
}
if(isset($_POST["submit"]))
{
echo count(array_filter($_POST["to_more"],"notempty"));
}
?>
<form name="f1" method="post">
<input type="text" name="to_more[]">
<input type="text" name="to_more[]">
<input type="text" name="to_more[]">
<input type="submit" name="submit" value="OK">
</form>
หรือทดสอบตัวนี้ก็ได้ครับ
$to_more = array("","second","third","","");
function notempty($val){
return !empty($val);
}
echo count(array_filter($to_more,"notempty"));
|
|
|
|
|
Date :
2014-01-30 14:58:50 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|