我没有使用php的经验,但我遇到了php的问题。
我有一个像这样的PHP代码:<div>
<ul>
<li><input type="checkbox" name="checkAll"
id="selectAll" class="checkbox"> Select All </li>
<?php
$count = 0;
foreach ($caseList as $testcase)
{
?>
<li><input type="checkbox" name="testcases"
class="checkbox"
value="<?php echo $testcase->id; ?>">
<?php echo $testcase->name; ?>
<?php $count++;?>
</li>
<?php
}
?>
<li> <?php echo "Total Test Case COunt: $count";?> </li>
</ul>
但我想在开始列表中打印“Total Test Case count”。我怎么能这样做?
答案 0 :(得分:1)
将count($caseList)
放在顶部。
<div>
<ul>
<li><input type="checkbox" name="checkAll" id="selectAll" class="checkbox"> Select All </li>
<li> <?php echo "Total Test Case COunt: " . count($caseList);?> </li>
<?php
$count = 0;
foreach ($caseList as $testcase)
{
?>
<li><input type="checkbox" name="testcases" class="checkbox" value="<?php echo $testcase->id; ?>"><?php echo $testcase->name; ?><?php $count++;?></li>
<?php
}
?>
</ul>
答案 1 :(得分:0)
您可以尝试使用count
函数获取没有计数器的数组长度。
$count = count($caseList);
所以你的最终代码可能就像
div>
<ul>
<li><input type="checkbox" name="checkAll" id="selectAll" class="checkbox"> Select All </li>
<?php
$total = count($caseList);
echo "Total Test Case Count: $total"
$count = 0;
foreach ($caseList as $testcase)
{
?>
<li><input type="checkbox" name="testcases" class="checkbox" value="<?php echo $testcase->id; ?>"><?php echo $testcase->name; ?><?php $count++;?></li>
<?php
}
?>
</ul>
答案 2 :(得分:0)
你需要从“li”标签移动增量
<div>
<ul>
<li><input type="checkbox" name="checkAll"
id="selectAll" class="checkbox"> Select All </li>
<?php
$count = 0;
foreach ($caseList as $testcase)
{
?>
<li><input type="checkbox" name="testcases"
class="checkbox"
value="<?php echo $testcase->id; ?>">
<?php echo $testcase->name; ?>
</li>
<?php
$count++;
}
?>
<li> <?php echo "Total Test Case COunt: $count";?> </li>
</ul>