Well, if I understood correctly now ...
INDEX.PHP
<?php
//Esta funcion añade los options en el select recibiendo el array de los meses
function afegirOption($nomMesos){
foreach($nomMesos as $nom){
echo "<option name='mes' value='".$nom."'>".$nom."</option>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$nomMesos = [1=>"Gener", 2=>"Febrer", 3=>"Març", 4=>"Abril", 5=>"Maig", 6=>"Juny", 7=>"Juliol", 8=>"Agost", 9=>"Septembre", 10=>"Octubre", 11=>"Novembre", 12=>"Desembre"];
//Sino se clica el boton submit entonces...
if (!isset($_POST['submit'])) {
?>
<!--Aquí he de crear la funcion que recoja el mes y mediante el select lo selecciones y te printee el mes con los años que tiene-->
<form method="post" action="ex05-4.php">
<p>Escull el mes :</p>
<select name="mes">
<!-- llamamos a la función y le enviamos el array -->
<?php afegirOption($nomMesos); ?>
<!--Aquí he de implementar el select bien pero no se como -->
</select> <p />
<input type="submit" name="submit" value="Ves">
</form>
<?php
//Si se envia bien el formulario entonces
} else {
$mesos = $_POST['mesos'];
}
?>
</body>
</html>
ex05-4.php
<html>
<body>
<?php calcularData() ?>
</body>
</html>
<?php
function calcularData(){
$nomMesos = [1=>"Gener", 2=>"Febrer", 3=>"Març", 4=>"Abril", 5=>"Maig", 6=>"Juny", 7=>"Juliol", 8=>"Agost",
9=>"Septembre", 10=>"Octubre", 11=>"Novembre", 12=>"Desembre"];
$any = date("Y");
$calcularData = $any."-".array_search($_POST["mes"], $nomMesos)."-01";
echo "El mes ".$_POST["mes"]." te ".date('t',strtotime($calcularData)). " dies.";
}
?>
There are several ways, but I think the simplest is this, in addition to this mode, you do not have to calculate traspàs or not ... since it does so automatically. The variable $ mesos I have not used it at all, but you can adapt it to $ nomMesos for your exercise.
EDITO: I add functions in php, remember that the functions can be inside the html tags or outside them, depending on what you want to do, in this case, I have left you out.
Now I hope I have helped you!
Option, all in one file:
<?php
$nomMesos = [1=>"Gener", 2=>"Febrer", 3=>"Març", 4=>"Abril", 5=>"Maig", 6=>"Juny", 7=>"Juliol", 8=>"Agost",
9=>"Septembre", 10=>"Octubre", 11=>"Novembre", 12=>"Desembre"];
//Esta funcion añade los options en el select recibiendo el array de los meses
function afegirOption($nomMesos){
foreach($nomMesos as $nom){
echo "<option name='mes' value='".$nom."'>".$nom."</option>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<!--Aquí he de crear la funcion que recoja el mes y mediante el select lo selecciones y te printee el mes con los años que tiene-->
<form method="post" action="">
<p>Escull el mes :</p>
<select name="mes">
<!-- llamamos a la función y le enviamos el array -->
<?php afegirOption($nomMesos); ?>
<!--Aquí he de implementar el select bien pero no se como -->
</select> <p />
<input type="submit" name="submit" value="Ves">
</form>
</body>
</html>
<?php
if (!empty($_POST)) {
calcularData();
}
function calcularData(){
$nomMesos = [1=>"Gener", 2=>"Febrer", 3=>"Març", 4=>"Abril", 5=>"Maig", 6=>"Juny", 7=>"Juliol", 8=>"Agost",
9=>"Septembre", 10=>"Octubre", 11=>"Novembre", 12=>"Desembre"];
$any = date("Y");
$calcularData = $any."-".array_search($_POST["mes"], $nomMesos)."-01";
echo "El mes ".$_POST["mes"]." te ".date('t',strtotime($calcularData)). " dies.";
}
?>
If you have any doubt about the reasoning of the exercise, you can ask me and I can explain step by step why the whole code, do not hesitate to write!
Optional
To not initialize $ nomMesos twice, above you can put:
global $nomMesos;
$nomMesos = [1=>"Gener", 2=>"Febrer", 3=>"Març", 4=>"Abril", 5=>"Maig", 6=>"Juny", 7=>"Juliol", 8=>"Agost",
9=>"Septembre", 10=>"Octubre", 11=>"Novembre", 12=>"Desembre"];
and then just below function calcularData(){
add global $nomMesos;
and so you do not have to re-add $ nomMesos = [****].