2009-10-27 63 views
0

我需要将数组中某一行的值更改为给定字符串,然后分解并保存数据。我使用下面的代码。更改数组中某一行的值

是该表的行。
目标是我想要更新的数组中的特定行。
nfv是我想放入数组中的新字符串。

<? 
$rowpre = $_GET['row']; 
$newfieldvalue = $_GET['nfv']; 
$row = --$rowpre; 
$data = file_get_contents("temp.php"); 
$csvpre = explode("###", $data); 
$i = 0; 
    foreach ($csvpre AS $key => $value){ 
     $i++; 
     if($i = $row){ 
      $info = explode("%%", $value); 
      $j = 0; 
       foreach ($info as $key => $value){ 
        $j++; 
        if($j == $target){ 
         /*change the value of this line to $newfieldvalue*/ 
        } 
       } 
     }   
    } 

$presave = implode("%%", $info); 
$save = implode("###", $presave); 
$fh = fopen("temp.php", 'w') or die("can't open file"); 
fwrite($fh, $save); 
fclose($fh); 
?> 

回答

2

你一定要明白,你可以索引到一个数组?如果你已经有一个数组元素的数字索引,先走一步,改变它:

$arr[$index] = "some new stuff"; 

奇妙的更新。

+0

所以在我爆炸信息后,我可以做一个$ info [$ target] =“新东西”; ? – mrpatg 2009-10-27 06:40:46

+0

你可以。 * Iff *我明白你的代码正确。它并没有在“告诉我你在做什么”的规模上居于高位。 – Joey 2009-10-27 06:54:27