Q:

How can i output the response of PHP shell_exec into a HTML table?

I have a PHP shell_exec command that outputs the following:
Cats
3
Dogs
9
Fish
2

Every second line is a number, that corresponds to the name of the animal on previous line, i would like the output in a HTML table for example:
HTML TABLE
------------
| Cats | 3 |
| Dogs | 9 |
| Fish | 2 |
------------

I think i need to create an array, but i am not sure how to align the animal name and number onto the same line. At the moment i have this:
<?php
    $array1 = array();
    exec( "Command", $Output );

?>
<html>

<table>
  <tr>
    <th>Animal</th>
    <th>Number</th>
  </tr>
  <tr>
    <td>*</td>
    <td>*</td>
  </tr>
  <tr>
    <td>*</td>
    <td>*</td>
  </tr>
  <tr>
    <td>*</td>
    <td>*</td>
  </tr>

  </tr>
</table>

</body>
</html>

How can i put this into a HTML Table?

A:

You can convert it to array with array-chunk after using explode to convert to array.
$str = 'Cats
3
Dogs
9
Fish
2';

$arr = explode(PHP_EOL, $str); //break each line
$arr = array_chunk($arr,2); // group each pair
foreach($arr as $e)
    $res[$e[0]] = $e[1]; // group each pair as key and value
print_r($res);

This will output:
Array
(
    [Cats] => 3
    [Dogs] => 9
    [Fish] => 2
)

You can now use this more easily to display by looping with foreach($res as $animal => $number)
Your HTML should be: 
<table>
  <tr>
    <th>Animal</th>
    <th>Number</th>
  </tr>
<?php foreach($res as $animal => $number)
    echo '<tr><td>'. $animal . '</td><td>' . $number . '</td></tr>'; ?>
</table>

