关于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>
http://i.stack.imgur.com/QQBle.jpg
我想用这个变量制作一个表格
第一栏输入表格名称 company []
对于第二个coloumn输入表单名称地址[]
第三个coloumn输入表单名称电话[]
我能为这些东西做些什么?
答案 0 :(得分:2)
只需更改此行:
<tr>
<?php foreach ($row as $field => $value): ?>
<td><input type="text" name="<?php echo $field; ?>[]" value="<?php echo $value; ?>" /></td>
<?php endforeach; ?>
</tr>