-3
Array (
  [0] => Array ( 
    [event_title] => Registration
    [event_id] => 17
    [location_id] => 113
  )
  [1] => Array (
    [event_title] => Sunday Collections
    [event_id] => 67
    [location_id] => 113
  )
  [2] => Array (
    [event_title] => School Tuition
    [event_id] => 68
    [location_id] => 113
  )
)

谁能告诉我如何从这个数组中提取和event_title提取?我实际上想以表格的形式显示它。event_idlocation_id

4

5 回答 5

4

该数组实际上非常简单

foreach($array as $item) {

    $event_title = $item['event_title'];
    $event_id = $item['event_id'];
    $location_id = $item['location_id'];    

}
于 2012-05-25T06:39:11.560 回答
3
<table><?php
    foreach($array as $arr) {
        echo '<tr><td>'.
            $arr['event_title'].
            '</td><td>'.
            $arr['event_id'].
            '</td><td>'.
            $arr['location_id'].
            '</td></tr>'.PHP_EOL;
     }
?></table>
于 2012-05-25T06:44:35.953 回答
3

要将其显示在表格中,您可以执行以下操作:

<table>
  <tr>
    <th>Event Title</th>
    <th>Event ID</th>
    <th>Location ID</th>
  </tr>
<?php foreach($array as $item): ?>
  <tr>
    <td><?php echo $item['event_title'] ?></td>
    <td><?php echo $item['event_id'] ?></td>
    <td><?php echo $item['location_id'] ?></td>
  </tr>
<?php endforeach; ?>
</table>
于 2012-05-25T06:45:24.550 回答
1
foreach ($arr as $event){
    echo $event["event_title"] . "\t" . $event["event_id"] . "\t". $event["location_id"] . "\n";
}
于 2012-05-25T06:42:19.623 回答
1
foreach ($array as $row) {
  ...
  echo "<td>{$row['event_title']}</td>";
  ...
}
于 2012-05-25T06:45:28.577 回答