本文介紹了在html表格中顯示一個(gè)數(shù)組的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我有這個(gè)數(shù)組:
Array
(
[page] => Array
(
[0] => add
[1] => edit
[2] => delete
[3] => search
)
[category] => Array
(
[0] => add
[1] => edit
[2] => export
)
)
我希望它顯示為這樣的 html 表格:
And I want it to be displayed as a html table like this:
Page - Category
add - add
edit - edit
delete - export
search
search
我嘗試了很多方法都沒有奏效,有什么解決方案嗎?
I tried in many ways but didn't work, any solutions?
推薦答案
假設(shè)這是 PHP 并且對(duì)齊只是基于數(shù)組的索引:
Assuming this is PHP and that the alignment is simply based on the index of the array:
<?php
$var['page'] = array('add', 'edit', 'delete', 'search');
$var['category'] = array('add', 'edit', 'export');
$pages = count($var['page']);
$categories = count($var['categories']);
$max = ($pages > $categories ? $pages : $categories);
echo '<table>';
for ($i = 0; $i < $max; $i++)
{
echo '<tr>';
echo "<td>{$var['page'][$i]}</td>";
echo "<td>{$var['category'][$i]}</td>";
echo '</tr>';
}
echo '</table>';
?>
這篇關(guān)于在html表格中顯示一個(gè)數(shù)組的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!