Ver Mensaje Individual
  #7 (permalink)  
Antiguo 26/07/2012, 09:25
Avatar de julio899
julio899
 
Fecha de Ingreso: junio-2011
Mensajes: 1
Antigüedad: 12 años, 10 meses
Puntos: 0
Mensaje Respuesta: recorrer array asociativo (multidimensional)

muchas Gracias, Me sirvió mucho y ahorro tiempo para generar una tabla donde las nombres de variables de los campos siempre variaban.
Aquí abajo les dejo el código. Que realice.
Código PHP:

$jsonDeepbit
=file_get_contents($url_deepbit_API);
$objDeepbit=json_decode($jsonDeepbit);

$array=json_decode($jsonDeepbit,true);
$workers=$array['workers'];
echo 
"<br><b>Cantidad de Trabajadores:</b>".count($workers);

echo 
"<table><caption>Trabajadores</caption>
<tr>
<th>Trabajador</th>
<th>alive</th>
<th>shares</th>
<th>stale</th>
</tr>"
;
foreach(
$workers as $item=>$key)
{
    echo 
"<tr>";
    echo 
"<td>$item</td>";
    echo 
"<td>".$key['alive']."</td>";
    echo 
"<td>".$key['shares']."</td>";
    echo 
"<td>".$key['stales']."</td>";
    echo 
"</tr>";
}  
echo 
"</table>"
Espero que a alguna persona le pueda ser de utilidad.