Created
September 10, 2019 13:50
-
-
Save msisaifu/5e1c50849d530951daff0cd2457c9025 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Crud { | |
public $person = []; | |
function create($array){ | |
array_push($this->person,$array); | |
} | |
function read($id){ | |
$index = $this->searchIndex($id); | |
echo "index number: {$id} name: {$this->person[$index]['name']}"; | |
// print_r ($this->person[$index]["name"]); | |
} | |
function update($id, $name){ | |
$index = $this->searchIndex($id); | |
$this->person[$index]["name"] = $name; | |
} | |
function delete($id){ | |
$index = $this->searchIndex($id); | |
unset($this->person[$index]); | |
} | |
function getPerson(){ | |
var_dump($this->person); | |
} | |
function searchIndex($id){ | |
foreach($this->person as $key => $value){ | |
if($value['id'] == $id){ | |
$index = $key; // [0] | |
} | |
} | |
return $index;//2 | |
} | |
} | |
$person = new Crud; | |
$person->create(["id" => 1, "name" => "zarif"]); | |
$person->create(["id" => 2, "name" => "saiful"]); | |
$person->create(["id" => 3, "name" => "John"]); | |
$person->create(["id" => 4, "name" => "Doe"]); | |
$person->read(2); | |
$person->update(2, "starc"); | |
$person->delete(2); | |
$person->getPerson(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment