11.09.2018 Views

Aprender a desarrollar un sitio Web con PHP y MySQL

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

24/4/2014 ENI Training - Libro online<br />

// Parámetros<br />

// - $tabla = tabla que debe mostrar el <strong>con</strong>tenido<br />

// - $titulo = título que hay que mostrar encima del <strong>con</strong>tenido<br />

// - $nivel = nivel de visualización<br />

if ($titulo != "") { // Si hay <strong>un</strong> título, mostrarlo.<br />

echo "".$titulo."";<br />

}<br />

// Comprobar si hay datos.<br />

if (isset($tabla)) { // Hay datos<br />

// Navegar por la tabla que se pasa como argumento.<br />

foreach ($tabla as $clave => $valor) {<br />

// mostrar la clave (<strong>con</strong> indentation f<strong>un</strong>ción<br />

// del nivel).<br />

// htmlentities() es la f<strong>un</strong>ción que <strong>con</strong>vierte los<br />

//caracteres especiales HTML<br />

echo str_pad(’’,12*$nivel, ’&nbsp;’).<br />

htmlentities($clave).’ = ’;<br />

// mostrar el valor<br />

if (is_array($valor)) { // comprueba si es <strong>un</strong>a tabla<br />

echo ’’;<br />

// Llama recursivamente a mostrar_tabla para<br />

// mostrar la tabla en cuestión<br />

mostrar_tabla($valor,’’,$nivel+1);<br />

} else { // es <strong>un</strong> valor escalonado<br />

// mostrar el valor.<br />

echo htmlentities($valor).’’;<br />

}<br />

}<br />

} else { // no hay datos<br />

echo ’’;<br />

}<br />

}<br />

// Declaración de las tablas.<br />

$tab_caracteristica_ESTEFANIA = array("nombre" => "PABLO",<br />

"profesión" => "ministro","edad" => 50);<br />

$tab_caracteristica_LUNA= array("nombre" => "ROBERTO",<br />

"profesión" => "agricultor","edad" => 45);<br />

$tab_persona[’ESTEFANIA’] = $tab_caracteristica_ESTEFANIA;<br />

$tab_persona[’LUNA’] = $tab_caracteristica_LUNA;<br />

// Mostrar <strong>un</strong>a tabla <strong>con</strong> dos dimensiones (Apellido/<br />

Características).<br />

mostrar_tabla($tab_persona,’Apellido/Características’);<br />

?><br />

Da como resultado:<br />

Apellido/Características<br />

ESTEFANIA =<br />

nombre = PABLO<br />

profesión = ministro<br />

edad = 50<br />

LUNA =<br />

nombre = ROBERTO<br />

http://www.eni-training.com/client_net/mediabook.aspx?idR=87313 10/15<br />

www.FreeLibros.me

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!