如何使用ForEaches回显数组数组

I have a form that asks the user to enter certain information about his or her cat, then the user may submit his information and it will be transferred to the database. I want this information to be echoed out into the view, so it will show each cat that has been submitted in a table. I think I am using the foreach correctly, but the table is not being populated with what I want.

Here is my code for my view:

<form action="/Anish/create" method="POST">
  <div>
    <label>Name</label><input type="text" name="name">
  </div>
  <div>
    <label>Age</label><input type="text" name="age">
  </div>
  <div>
    <label>Gender</label><input type="text" name="gender">
  </div>
  <div>
    <label>Species</label><input type="text" name="species">
  </div>
  <div>
    <label>Eye Color</label><input type="text" name="eye_color">
  </div>
    <div>
    <label>Color</label><input type="text" name="color">
  </div>
    <div>
    <label>Description</label><input type="text" name="description">
  </div>
    <div>
    <label>marital status</label><input type="text" name="marital_status">
  </div>
  <br>
  <button type="submit" class="btn btn-block btn-primary span1">Add cat</button>
</form>
<br/>
<br/>
<br/><br/>
<table border="1">
<tr>  
<td>Name</td>
<td>Gender</td>
<td>Age</td>
<td>Species</td>
<td>Eye Color</td>
<td>Color</td>
<td>Description</td>
<td>Marital Status</td>
</tr>
<td>
<?php 
  foreach ($data as $cats){
    echo ($cats);
  }
?>
</td>
</table>

And here is my code for the controller:

class Anish extends Public_Controller
{
  public function __construct()
  {
   parent::__construct();
    // Load the required classes
    $this->load->model('Anish_m');
    // $this->lang->load('anish');
  }
  public function index()
  {
$data=array( 
'cats'=>$this->Anish_m->get(),
  );
// var_dump($data);die;
    $this->template
      ->set('data', $data)
      ->build('index', $data);
  }

  public function create() {
    $Anish = array(
      'name' => $this->input->post('name'),
      'age' => $this->input->post('age'),
      'gender' => $this->input->post('gender'),
      'species' => $this->input->post('species'),
      'eye_color' => $this->input->post('eye_color'),
      'color' => $this->input->post('color'),
      'description' => $this->input->post('description'),
      'marital_status' => $this->input->post('marital_status')
    );
    $createCat=$this->Anish_m->create($Anish);
      redirect('/Anish');
  }
}

I appreciate any help.

Your cells aren't being echoed into new rows.

replace

<td>
<?php 
  foreach ($data as $cats){
    echo ($cats);
  }
?>
</td>

with

<?php 
  foreach ($cats as $cat){
    echo '<tr>'
     . '<td>' . $cat['name'] . '</td>'
     // etc...
     . '</tr>';
  }
?>

The exact language depends on what your data array is.

Ah, I figured it out. Here is what it looks like:

<form action="/Anish/create" method="POST">
  <div>
    <label>Name</label><input type="text" name="name">
  </div>
  <div>
    <label>Age</label><input type="text" name="age">
  </div>
  <div>
    <label>Gender</label><input type="text" name="gender">
  </div>
  <div>
    <label>Species</label><input type="text" name="species">
  </div>
  <div>
    <label>Eye Color</label><input type="text" name="eye_color">
  </div>
    <div>
    <label>Color</label><input type="text" name="color">
  </div>
    <div>
    <label>Description</label><input type="text" name="description">
  </div>
    <div>
    <label>marital status</label><input type="text" name="marital_status">
  </div>
  <br>
  <button type="submit" class="btn btn-block btn-primary span1">Add cat</button>
</form>
<br/>
<br/>
<br/><br/>
<table border="1">
<tr>  
<td>Name</td>
<td>Gender</td>
<td>Age</td>
<td>Species</td>
<td>Eye Color</td>
<td>Color</td>
<td>Description</td>
<td>Marital Status</td>
</tr>
<td><?php foreach ($cats as $cat):?>
  <?php echo ($cat['name']);?><br/>
<?php endforeach;?></td>
<td><?php foreach ($cats as $cat):?>
  <?php echo ($cat['gender']);?><br/>
<?php endforeach;?></td>
<td><?php foreach ($cats as $cat):?>
  <?php echo ($cat['age']);?><br/>
<?php endforeach;?></td>
<td><?php foreach ($cats as $cat):?>
  <?php echo ($cat['species']);?><br/>
<?php endforeach;?></td>
<td><?php foreach ($cats as $cat):?>
  <?php echo ($cat['eye_color']);?><br/>
<?php endforeach;?></td>
<td><?php foreach ($cats as $cat):?>
  <?php echo ($cat['color']);?><br/>
<?php endforeach;?></td>
<td><?php foreach ($cats as $cat):?>
  <?php echo ($cat['description']);?><br/>
<?php endforeach;?></td>
<td><?php foreach ($cats as $cat):?>
  <?php echo ($cat['marital_status']);?><br/>
<?php endforeach;?></td>
</table>