2015-06-18 105 views
-5

我有一個快速的問題。如何以特定格式顯示數組中的數據。在表中顯示php數組

我想表看起來像這樣:

名稱                                                                                 名稱                                                                                 名稱
的姓氏和名字數組值 的姓氏和名字數組值   的姓氏和名字數組值

請請注意,第一個和名稱值是相同的字段。

+2

有太多可能的答案,或者對於這種格式太好的答案太長。請添加詳細信息以縮小答案集或隔離可在幾個段落中回答的問題。我建議您找到一個開發論壇(可能是[quora](http://www.quora.com/Computer-Programming) )?)來計算一般性。然後,當您遇到特定的編碼問題時,請回到StackOverflow,我們很樂意提供幫助。 –

+0

請給我們你完成這個任務的嘗試,我們不是你的個人團隊的程序員。 –

+0

你的數組是什麼樣的? – PHPhil

回答

1

不確定這是你問的問題還是你的數組看起來像但可能會有幫助。

<?php 

$array = array(array('FirstName', 'LastName'),array('FirstName1', 'LastName1'),array('FirstName2', 'LastName2'),array('FirstName3', 'LastName3')); 

//count number inner arrays 
$number = count($array); 

// create table <table>, create table row <tr> 
echo "<table><tr>"; 

//create table header number of times there are inner arrays 
for($x = 0; $x<$number; $x++){ 

    // create table data <td>, could also use table header <th> 
    echo "<td>name</td>"; 

} 

    //close table row and open a new one 
    echo "</tr><tr>"; 

//iterate through the array 
foreach($array as $value){ 

    // create the real table data 
    echo "<td> $value[0] $value[1]</td>"; 

} 

// close table row and table 
echo "</tr></table>"; 

?> 
+0

謝謝,我會給它一個鏡頭.. –

+0

其實我找到了一個解決方案。我所做的是我使用了css和li語句。 –