我有一个来自 Wordpress 页面的数据库数组:dev-user-20190424.php<?php$wb_users = array( array( "Username" => "Azmina", "Level" => "form-5", "School" => "KOLEJ D PATINGGI ABANG HJ ABDILLAH, SARAWAK", "SchoolID" => 4522, ), array( "Username" => "Gudako", "Level" => "form-5", "School" => "KOLEJ D PATINGGI ABANG HJ ABDILLAH, SARAWAK", "SchoolID" => 4522, ), array( "Username" => "Takatosaijo29", "Level" => "form-5", "School" => "SEKOLAH MENENGAH KEBANGSAAN BAHANG, SABAH", "SchoolID" => 4210, ), array( "Username" => "Obon", "Level" => "form-5", "School" => "SEKOLAH MENENGAH KEBANGSAAN BAHANG, SABAH", "SchoolID" => 4210, ), array( "Username" => "Rayana12", "Level" => "form-5", "School" => "SEKOLAH MENENGAH KEBANGSAAN BAHANG, SABAH", "SchoolID" => 4210, ), array( "Username" => "kaiyuanbeh", "Level" => "form-5", "School" => "SEKOLAH MENENGAH KEBANGSAAN PERMATANG RAWA, PULAU PINANG", "SchoolID" => 4250, ), array( "Username" => "Divyabharthi", "Level" => "form-5", "School" => "SEKOLAH MENENGAH KEBANGSAAN PETALING, WP KL", "SchoolID" => 4244, ), array( "Username" => "blackchocolatecake", "Level" => "form-4", "School" => "SEKOLAH MENENGAH KEBANGSAAN POI LAM, PERAK", "SchoolID" => 4375, ), );所以我想要实现的是通过循环数组 $wb-users 来显示另一个 WordPress 页面上的用户总数,如果 SchoolID 与当前用户学校 id 变量匹配,则对其进行计数。然后页面上会显示用户总数。
2 回答
牧羊人nacy
TA贡献1862条经验 获得超7个赞
我相信这基本上就是你要找的。
$schoolID = 4522;
$studentTotal = 0;
for ($i = 0; $i < count($wb_users); $i++) {
if ($wb_users[$i]['SchoolID'] === $schoolID) {
$studentTotal++;
}
}
您需要 1. 循环遍历主数组中的数组。2. 将“SchoolID”键与您的学校 ID 变量进行比较。3. 匹配时增加计数器。
- 2 回答
- 0 关注
- 125 浏览
添加回答
举报
0/150
提交
取消