-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_titleevent_idを抽出する方法を誰か教えてもらえますか? location_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>
  <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 に答える
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 に答える
1
foreach ($array as $row) {
  ...
  echo "<td>{$row['event_title']}</td>";
  ...
}
于 2012-05-25T06:45:28.577 に答える
1
foreach ($arr as $event){
    echo $event["event_title"] . "\t" . $event["event_id"] . "\t". $event["location_id"] . "\n";
}
于 2012-05-25T06:42:19.623 に答える