I been trying to unset a value from an array without success, I'm trying to be able to edit values from a CSV file. When I click edit it should open the values load it locally unset it and re save the array with the new value. My problem is that the all the values are being added twice along with the new edit value.
This is my edit function
class edit extends index{ public function GET(){ $Remail = ($_REQUEST['email']); $filename = 'testfile.csv'; $lines = file($filename); foreach($lines as $info) { $CSVString = explode(',', $info); $this->email = trim(explode("=", $CSVString[0])[1]); if ($Remail === $this->email){ $this->Fname = trim(explode("=", $CSVString[1])[1]); $this->Lname = trim(explode("=", $CSVString[2])[1]); unset($CSVString[0]); } $this->person = array('Email'=>$this->email,'FirstName' =>$this- >Fname, 'LastName' =>$this->Lname); $this->save($this->person); } echo '<form action="index.php?page=adduser" method="POST"> <label for="email">Email:</label></br> <input type="text" name="Email" value="' . $Remail . '"></br> <label for="fname">First Name:</label></br> <input type="text" name="Fname" value="' . $this->Fname . '"></br> <label for="lname">Last Name:</label></br> <input type="text" name="Lname" value="' . $this->Lname . '"></br> <input type="submit"> </form>'; } this is my save function
public function save($arr){ $filename = 'testfile.csv'; $myfile = fopen($filename, "a+") or die("Unable to open file!"); foreach($arr as $key => $value){ $new [] = $key.'='.$value; $final = implode(",", $new); } fwrite($myfile, $final.PHP_EOL); fclose($myfile); } And this is the adduser that the form is calling
class adduser extends index { public function GET(){ include('add.html'); } public function POST($Fname, $Lname, $Email){ $this->Fname = $Fname; $this->Lname = $Lname; $this->Email = $Email; $this->person = array('Email'=>$this->Email,'FirstName' =>$this->Fname, 'LastName' =>$this->Lname); $this->save($this->person);