Can anyone tell me why when stepping through an array and trying to delete a
specific element in the array it deletes not only the one that I want it to
delete, but also the first and last element in the array as well.?

Here is the situation:
    I am retrieving information from a text file, dumping it to any array of
arrays.  Then searching for the specific element to delete it.  After the
deletion it should re-write the information back to the text file. Without
the element that I wanted to delete.  But it also deletes the first and last
element.

<?
if(!empty($HTTP_POST_VARS)) {
  foreach(file($storelist) as $store => $data) {
    foreach($stores[$i] = explode(":", $data) as $key => $val) {
      $stores[$i][$key] = trim($val);
    }
    $i++;
  }
  $fp = @ fopen($storelist, "w") or die("<b>Fatal Error:</b> could not open
$storelist for edit<br>\n");
  foreach($HTTP_POST_VARS as $key => $val) {
    unset($stores[$val]);
  }
  for($i=0; $i<count($stores); $i++) {
    if(!isset($stores[$i])) continue;
    fwrite($fp,
$stores[$i][0].":$j:".$stores[$i][2].":".$stores[$i][3].":".$stores[$i][4]."
:".$stores[$i][5].":".$stores[$i][6].":".$stores[$i][7].":".$stores[$i][8]."
\n");
    $j++;
  }
  fclose($fp);
}
unset($HTTP_POST_VARS);
?>
--
Joshua E Minnie
CIO
[EMAIL PROTECTED]

"Don't work for recognition, but always do work worthy of recognition."



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to