我需要制作表格。首先,我需要一个选择 让您选择group1,group 2或两者。 其次,有一个复选框,询问您是否要显示未通过课程的组中的人员。
<?php
$NotesGroupe1 = array(
"HARG200181" => array("Guillaume", "Harvey", "M", 36, 90, 70, 76),
"CHAM010283" => array("Marc-André", "Charpentier", "M", 34, 80, 73, 96),
"TREV290991" => array("Valérie", "Tremblay", "F", 26, 70, 71, 69),
"PELL180584" => array("Laurence", "Pelletier", "F", 30, 65, 89, 76),
"MALF110194" => array("Francis", "Maltais", "M", 20, 61, 50, 59),
"GAUM220654" => array("Martine", "Gauthier", "F", 60, 65, 40, 76),
);
$NotesGroupe2 = array(
"GIRM230383" => array("Marc-Olivier", "Girard", "M", 31, 75, 85, 56),
"TREM300878" => array("Michel", "Tremblay", "M", 36, 50, 50, 55),
"POID250468" => array("Diane", "Poitras", "F", 46, 61, 75, 59),
"LEML180586" => array("Laurence", "Lemieux", "F", 31, 80, 89, 100),
"VANL130395" => array("Jeff", "Van Cleef", "M", 19, 61, 68, 33)
);
之后,您需要一个无线电按钮,告诉您是否需要等级 男性或女性或两者兼而有之。
<form method="GET">
<div class="menu">
<?php include 'menu.php';?>
</div>
Choisir une groupe :
<select name="groupe">
<option value='0'>Groupe 1</option>
<option value='1'>Groupe 2</option>
<option value='3'>Groupe 1 & 2</option>
</select>
<br>
Affichez seulement les notes des élèves en situation d'échec.
<input type="checkbox" name="echec" value="selectionner"/><br>
Affichez hommes & femmes : <input type="radio" name="sexe" value="M|F" checked="checked"/>
Affichez seulement les hommes : <input type="radio" name="sexe" value="M"/>
Affichez seulement les femmes : <input type="radio" name="sexe" value="F"/>
<br>
<input type="submit" value="Soumettre"/>
<?php
require_once("tableaux.php");
if(isset($_GET["groupe"])&& isset($_GET["sexe"])){
$groupeNumber = $_GET["groupe"];
$sexe = $_GET["sexe"];
$pregSexe = "/" . $sexe . "/im";
$groupe = "";
if($groupeNumber == 0){
$groupe = $NotesGroupe1;
}else if ($groupeNumber == 1){
$groupe = $NotesGroupe2;
}
else{
$groupe=$NotesGroupe1+$NotesGroupe2;
}
if ( preg_match($pregSexe, $sexe)){
}else if ( preg_match($pregSexe, $sexe) ){
}
else if( preg_match($pregSexe, $sexe){
}
if(isset($_GET["echec"]){
$echec = $_GET["echec"];
if ($echec == true){
}
else{
}
}
}
?>
我没有完成代码,我似乎无法将与性别相关的组中的失败成绩联系起来。我无法修改数组,所以有什么可以帮助我。感谢
答案 0 :(得分:0)
您可以将array_filter()
与自定义函数一起使用,以根据正则表达式减少数组。
$NotesGroupe1 = array(
"HARG200181" => array("Guillaume", "Harvey", "M", 36, 90, 70, 76),
"CHAM010283" => array("Marc-André", "Charpentier", "M", 34, 80, 73, 96),
"TREV290991" => array("Valérie", "Tremblay", "F", 26, 70, 71, 69),
"PELL180584" => array("Laurence", "Pelletier", "F", 30, 65, 89, 76),
"MALF110194" => array("Francis", "Maltais", "M", 20, 61, 50, 59),
"GAUM220654" => array("Martine", "Gauthier", "F", 60, 65, 40, 76),
);
$groupe = $NotesGroupe1 ;
$sexe = 'F'; // arbitrary value but come from your $_POST.
$pregSexe = '/'.$sexe.'/im' ; // eg. '/F/im', '/M/im', or '/M|F/im'
$groupe = array_filter($groupe, function($element) use ($pregSexe) {
return preg_match($pregSexe, $element[2]) ;
});
print_r($groupe);
该函数是一个匿名函数,$pregSexe
使用use()
在其范围内访问true
。此函数返回一个布尔值:false
保持,"F"
拒绝。
在上面的代码中,只有第三个键Array (
[TREV290991] => Array ([0] => Valérie [1] => Tremblay [2] => F [3] => 26 [4] => 70 [5] => 71 [6] => 69 )
[PELL180584] => Array ([0] => Laurence [1] => Pelletier [2] => F [3] => 30 [4] => 65 [5] => 89 [6] => 76 )
[GAUM220654] => Array ([0] => Martine [1] => Gauthier [2] => F [3] => 60 [4] => 65 [5] => 40 [6] => 76 )
)
的数组元素保留在最终数组中。
library(tidyverse)
mtcars <- as_tibble(mtcars)
mtcars$cyl <- as.factor(mtcars$cyl)
model1 <- glm(mpg ~ cyl + hp, data = mtcars)
summary(model1)