Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 读取csv并将数据转换为可编辑表单_Php_Html_Csv_Foreach - Fatal编程技术网

Php 读取csv并将数据转换为可编辑表单

Php 读取csv并将数据转换为可编辑表单,php,html,csv,foreach,Php,Html,Csv,Foreach,关于csv解析和foreach循环的问题 <?php //output Array ( [0] => Array ( [company] => A Company [address] => A Address [telephone] => A Telephone ) [1] => Array ( [company] => B Compan

关于csv解析和foreach循环的问题

<?php

  //output
 Array   
(  

  [0] => Array
    (
        [company] => A Company
        [address] => A Address
        [telephone] => A Telephone
    )

  [1] => Array
    (
        [company] => B Company
        [address] => B Address
        [telephone] => B Telephone
    )

  [2] => Array
    (
        [company] => C Company
        [address] => C Address
        [telephone] => C Telephone
    )

)
?>

<table border="0" cellspacing="1" cellpadding="3">
<tr>
    <?php foreach ($csv->titles as $value): ?>
    <th><?php echo $value; ?></th>
    <?php endforeach; ?>
</tr>
<?php foreach ($csv->data as $key => $row): ?>
<tr>
    <?php foreach ($row as $value): ?>
    <td><input type="text" name="field[]" value="<?php echo $value; ?>" /></td>
    <?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>


只需更改这一行:

<tr>
    <?php foreach ($row as $field => $value): ?>
    <td><input type="text" name="<?php echo $field; ?>[]" value="<?php echo $value; ?>" /></td>
    <?php endforeach; ?>
</tr>


这使行等于0 0 1 1 2 2 2 2,但我需要列数等于0 1 2 0 1 2 0 1 2