Php - 我必须在PHP中创建2个函数,我不知道如何实现它们 [英] Php - I have to create 2 functions in PHP and I do not know how to implement them

查看:62
本文介绍了Php - 我必须在PHP中创建2个函数,我不知道如何实现它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

Hi everyone!. I have a code that works but I have to redo it for a new one and do the next exercise. The output of the code is the same, so what you see on the screen will be the same as what you see now in this php code. If someone has the solution, I would appreciate it.

Statement:
Functions that call other functions.
Take advantage of the code. Rewriting the option function ($szMes) by 
fesOpcions ($ matrix) that includes all the tasks of creating the option. This
new function will take as argument a matrix and iterate on the key values ​​for
enter the options. Write a second function fesQuadreCombinat ($ name, $ matrix)
which generates all the necessary HTML code to make the combo box. This function generates an error message in case the second argument is not an array. this function must call fesOpcions ($ matrix)

Suggestion: Use is_array () Sorry for my English i am from Spain here the code.









代码:





Code:

<?php

//Creació de la matriu

$mesos=array(

  'gener'=>31,

  'febrer'=>'28 dies, en any de traspàs 29',

  'març'=>31,

  'abril'=>30,

  'maig'=>31,

  'juny'=>30,

  'juliol'=>31,

  'agost'=>31,

  'setembre'=>30,

  'octubre'=>31,

  'novembre'=>30,

  'desembre'=>31

);

 //En este ejercicio he de crear dos funciones pero no se como implementarlas para hacer el ejercicio

//Definició de la funció.

//La funció ucfirst posa la primera lletra en majúscula

function opcio($szMes){

  echo "<option value=\"$szMes\">" .ucfirst($szMes). "</option>\n";

}

 

/*function fesOpcions($matriu){

	

}

function fesQuadreCombinat($nom, $matriu){

	

}*/

?>

<html>

<head>

    <meta content="text/html; charset=UTF-8" http-equiv="content-type">

    <title>Funcions que criden altres funcions</title>

</head>

 

<body>

<h2>Funcions que criden altres funcions</h2>

 

<?php

if(!isset ($_POST['submit'])){

    ?>

    <form method="post" action="ex05-6.php">

    <p>Si us plau, escolliu un mes</p>

 

    <!--Creamos el select -->

	<select name="mes">

    <?php

    //Crea opcions emprant la matriu de la funció

      foreach ($mesos as $k => $v){

        opcio($k);

      }

    ?>

    </select>

    <p />

    <input type="submit" name="submit" value="Ves" />

    </form>

<?php

} else {

      $mes = $_POST['mes'];

      if ($mes == 'febrer'){

        echo "El mes de febrer té " . $mesos['febrer'] . ".";

      }else{

        echo "El mes de $mes té $mesos[$mes] dies.";

      }

}

?>

</body>

</html>





我的尝试:



我不知道如何创建这两个我失去的功能。代码必须与下面的代码相同但功能。



What I have tried:

I do not know how to create this 2 functions i am lost . The code has to do the same as the below but with functions.

推荐答案

szMes)
fesOpcions(
szMes) by fesOpcions (


矩阵)包括创建选项的所有任务。这个
的新函数将把矩阵作为参数,并迭代
的键值输入选项。写第二个函数fesQuadreCombinat(
matrix) that includes all the tasks of creating the option. This new function will take as argument a matrix and iterate on the key values ​​for enter the options. Write a second function fesQuadreCombinat (


name,


这篇关于Php - 我必须在PHP中创建2个函数,我不知道如何实现它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆