2012-05-25 130 views
-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_idlocation_id从这个数组?我想要以表格的形式显示它。通过复杂的PHP数组循环

+5

数组并不复杂。 – flowfree

+1

到目前为止你尝试过什么,你卡在哪里?请向我们展示您创建的代码,以便我们找出最新的错误。 – Bjoern

+0

像'for($ x = 0; $ x Ben

回答

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> 
4

事实上,该阵列非常简单

foreach($array as $item) { 

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

} 
1
foreach ($arr as $event){ 
    echo $event["event_title"] . "\t" . $event["event_id"] . "\t". $event["location_id"] . "\n"; 
} 
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> 
1
foreach ($array as $row) { 
    ... 
    echo "<td>{$row['event_title']}</td>"; 
    ... 
}