Arrangements in PHP with Netbeans IDE

1

I need to make a record in PHP where each person is included in the list.

I must evaluate if the name of the existing color in a second arrangement that contains the name of the color and the meaning of each one, in case of finding it, it is necessary to write in a last column of the table shown, the meaning of the color, otherwise you must write the phrase "The meaning can not be found".

So far I have only been able to do the lists, but it does not show me the meaning of the color, I would appreciate it.

This is my code so far.

<!DOCTYPE html>
<html>
    <head>
        <title>Arreglos Listado Agenda Telefonica</title>
        <meta http-equiv="Content-Type"
              content="text/html; charset=ISO-8859-1" />
    </head>
    <body>
        <h3>Listado Agenda</h3>
        <?php
        /* En este programa se va a especificar la forma de
         * declarar arreglos y acceder a la información que contiene
         */
        //Arreglo con llaves numéricas
        $cabecera=array("Nombre","Direccion","Telefono", "Fecha de Cumpleanos", "Color Favorito", "Significado");
        $nombres=array("Jimmy Riera","Valera","041412345678", "05/01/1976", "Amarillo");
        $direccion=array("Antonio Lopez","Motatan","041245612378", "08/02/1976", "Rojo");
        $telefono=array("Paola Reverol","Pampan","04145551212", "15/12/2000", "Verde");
        $fechaCumple=array("Manuela Saez","Trujillo","0272-5552212", "31/06/1999", "Rosado");
        $color=array("Juan Rojo","Valera","041412345678", "05/01/1976", "Azul");
        $directorio=array($cabecera,$nombres,$direccion,$telefono,$fechaCumple,$color);
        $key=array("Amarillo", "Riqueza-Pureza");
        $result = isset($colores[$key]) ? $array[$key] : "No se encuentra el significado";
        ?>
<table border="1" width="60%" cellspacing="0">
<?php
foreach ($directorio as $fila){
        echo "<tr>";
        foreach ($fila as $celda){
                echo "<td> $celda </td>";
                }
        echo "</tr>";
        }
?>
</table>
     </p>
    </body>
</html>
    
asked by Alekxander NieSer 31.03.2017 в 04:26
source

1 answer

0

To answer your question I made slight changes to your code, changed the array $cabecera to $cabeceras and removed it from the array $directorio to be able to iterate over both arrays

The code stayed this way

<!DOCTYPE html>
<html>
<head>
  <title>Arreglos Listado Agenda Telefonica</title>
  <meta http-equiv="Content-Type"
  content="text/html; charset=ISO-8859-1" />
</head>
<body>
  <h3>Listado Agenda</h3>
  <?php
  /* En este programa se va a especificar la forma de
   * declarar arreglos y acceder a la información que contiene
   */
  //Arreglo con llaves numéricas
  // Arreglo de cabeceras
  $cabeceras=array("Nombre","Direccion","Telefono", "Fecha de Cumpleanos", "Color Favorito", "Significado");
  // Directorio
  $nombres=array("Jimmy Riera","Valera","041412345678", "05/01/1976", "Amarillo");
  $direccion=array("Antonio Lopez","Motatan","041245612378", "08/02/1976", "Rojo");
  $telefono=array("Paola Reverol","Pampan","04145551212", "15/12/2000", "Verde");
  $fechaCumple=array("Manuela Saez","Trujillo","0272-5552212", "31/06/1999", "Rosado");
  $color=array("Juan Rojo","Valera","041412345678", "05/01/1976", "Azul");
  $directorio=array($nombres,$direccion,$telefono,$fechaCumple,$color);
  $key=array("Amarillo" => "Riqueza-Pureza");
  ?>
  <table border="1" width="60%" cellspacing="0">
    <?php
    // Iteramos sobre las cabeceras
    echo "<tr>";
    foreach ($cabeceras as $cabecera) {
      echo "<td> $cabecera </td>";
    }
    echo "</tr>";
    // Iteramos sobre el directorio
    foreach ($directorio as $fila) {
      echo "<tr>";
      foreach ($fila as $llave => $celda) {
        echo "<td> $celda </td>";
        // Revisamos que nos encontramos en el índice que contiene el color e imprimimos
        // el sifnificado
        if ($llave === 4) {
          echo "<td>";
          echo isset($key[$celda]) ? $key[$celda] : "No se encuentra el significado";
          echo "</td>";
        }
      }
      echo "</tr>";
    }
  ?>
  </table>
</body>
</html>

Print this:

Recommendation:

This has nothing to do with the question, it is a simple recommendation that was once made to me and has helped me to program.

I suggest that for readability keep your names of variables consistent with what they contain, for example, the $nombres fix could be called $jimmy or $persona1 and so on

    
answered by 31.03.2017 / 05:33
source