Php 使数组表可编辑并可保存

Php 使数组表可编辑并可保存,php,arrays,csv,html-table,edit,Php,Arrays,Csv,Html Table,Edit,我有一个CSV文件,我已经把它变成了一个数组,它成功地将它打印到屏幕上的一个表中 但我想做的是,有一个按钮,使表格可编辑,然后数据可以更改和更新 我对PHP相当陌生,所以我甚至不知道从哪里开始 这就是我用来将数组转换为表的方法: //This converts an array to a table function array2table($array, $recursive = false, $null = ' ') { // Sanity check if (empty(

我有一个CSV文件,我已经把它变成了一个数组,它成功地将它打印到屏幕上的一个表中

但我想做的是,有一个按钮,使表格可编辑,然后数据可以更改和更新

我对PHP相当陌生,所以我甚至不知道从哪里开始

这就是我用来将数组转换为表的方法:

//This converts an array to a table
function array2table($array, $recursive = false, $null = ' ')
{
// Sanity check
if (empty($array) || !is_array($array)) {
    return false;
}

if (!isset($array[0]) || !is_array($array[0])) {
    $array = array($array);
}

// Start the table
$table = "<table>\n";

// The header
$table .= "\t<tr>";

// Take the keys from the first row as the headings
foreach (array_keys($array[0]) as $heading) {
    if($heading ==0){
        $heading = "Full Name";
    }else if($heading == 1){
        $heading = "Weight";
    }else if($heading == 2){
        $heading = "Weight of belongings";
    }else if($heading == 3){
        $heading = "Total Weight";
    }else if($heading == 4){
        $heading = "Unassemblium Required";
    }else if($heading == 5){
        $heading = "Reassemblium Required";
    }else if($heading == 6){
        $heading = "Cost of Unassemblium";
    }else if($heading == 7){
        $heading = "Cost of Reassemblium";
    }else if($heading == 8){
        $heading = "Total cost of journey";
    }

   $table .= '<th>' . $heading. '</th>';

}
$table .= "</tr>\n";

// The body
foreach ($array as $row) {
    $table .= "\t<tr>" ;

    foreach ($row as $cell) {

        $table .= '<td>';


        // Cast objects
        if (is_object($cell)) { $cell = (array) $cell; }

        if ($recursive === true && is_array($cell) && !empty($cell)) {
            // Recursive mode
            $table .= "\n" . array2table($cell, true, true) . "\n";
        } else {
            $table .= (strlen($cell) > 0) ?
                htmlspecialchars((string) $cell) :
                $null;
        }

        $table .= '</td>';
    }

    $table .= "</tr>\n";
}

$table .= '</table>';
return $table;
}
//这将数组转换为表
函数array2table($array,$recursive=false,$null='')
{
//健康检查
if(空($array)| |!is_array($array)){
返回false;
}
如果(!isset($array[0])| |!is_array($array[0])){
$array=数组($array);
}
//开桌
$table=“\n”;
//标题
$table.=“\t”;
//将第一行的键作为标题
foreach(数组_键($array[0])作为$heading){
如果($heading==0){
$heading=“全名”;
}否则,如果($heading==1){
$heading=“重量”;
}否则,如果($heading==2){
$heading=“物品重量”;
}否则,如果($heading==3){
$heading=“总重量”;
}否则,如果($heading==4){
$heading=“需要取消装配”;
}否则,如果($heading==5){
$heading=“需要重新组装”;
}否则,如果($heading==6){
$heading=“拆卸成本”;
}否则,如果($heading==7){
$heading=“重新组装成本”;
}否则,如果($heading==8){
$heading=“旅程总成本”;
}
$table.=''.$heading.'';
}
$table.=“\n”;
//身体
foreach($array作为$row){
$table.=“\t”;
foreach($行作为$单元格){
$table.='';
//投射物
if(is_object($cell)){$cell=(数组)$cell;}
if($recursive==true&&is_数组($cell)&&!空($cell)){
//递归模式
$table.=“\n”.array2table($cell,true,true)。“\n”;
}否则{
$table.=(strlen($cell)>0)?
htmlspecialchars((字符串)$cell):
$null;
}
$table.='';
}
$table.=“\n”;
}
$table.='';
返回$table;
}
我需要帮助为用户提供使该表可编辑的选项,然后将其保存到数组中。我可以补充什么