php - How to use keys to be as indicator? -



php - How to use keys to be as indicator? -

as exploring arrays , how utilize it

i encounter unusual array.

i trying accomplish ouput using array have posted below.

how can done?

<table> <tr> <th>dogs</th> <th>cats</th> <th>birds</th> </tr> <tr> <td><?php echo $dogs;?></td> <td><?php echo $cats;?></td> <td><?php echo $birds;?></td> </tr> </table> array ( [cats] => array ( [0] => western farsi [1] => ragdoll [2] => siberian [3] => savannah ) [dogs] => array ( [0] => husky [1] => bulldog [2] => beagle [3] => labrador ) [birds] => array ( [0] => parrot [1] => owl [2] => eagle [3] => love birds ) )

this output need get:

dogs cats birds husky western farsi parrot bulldog ragdoll owl beagle siberian eagle labrador savannah love birds

you need loop them first, cannot outright echo arrays:

$animals = array( 'dogs' => array('husky', 'bulldog', 'beagle', 'labrador'), 'cats' => array('persian', 'ragdoll', 'siberian', 'savannah'), 'birds' => array('parrot', 'owl', 'eagle', 'love birds'), ); ?> <table cellpadding="10"> <tr><th>dogs</th><th>cats</th><th>birds</th></tr> <?php $types = array_keys($animals); for($i = 0; $i < count($animals['cats']); $i++) { echo '<tr>'; foreach($types $type) { echo '<td>' . $animals[$type][$i] . '</td>'; } echo '</tr>'; } ?> </table>

sample output

php html arrays

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -