I'm currently working on a school project and can't manage to figure out how to implode and explode the array properly. My goal is to be able to add new users, be able to delete users, and update users. I need to get my key value pair correctly in order to achieve that.
Thank you
<?php
class index {
function __construct(){}
My CSV read results is the following
Array
(
[Email = [email protected]] => FirstName = fake_firstname
)
public function display() {
$filename = 'testfile.csv';
$lines = file($filename);
$data = array();
echo "<tr>
<th>Email</th>
<th>First</th>
<th>Last</th>
</tr><br>";
foreach($lines as $info) {
list($key, $value) = explode(',', $info);
$result[$key] = $value;
echo "<pre>";
print_r($result);
echo "</pre>";
}
}
public function add($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);
print_r($this->person);
}
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."\r\n");
fclose($myfile);
}
My CSV saved results is the following Email = [email protected],FirstName = fake_firstname,LastName = fake_lastname
public function form(){
include('add.html');
}
} // close off class index
?>