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
Post a Comment