Having problems deleting an element from an array
| From: | Joshua E Minnie | Date: | Fri, 05 Apr 2002 20:21:21 +0000 |
| Subject: | Having problems deleting an element from an array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-91794@lists.php.net to get a copy of this message | ||
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
josh@acsurf.net
"Don't work for recognition, but always do work worthy of recognition."