In this example, I have shared What is dependency injection in PHP. Dependency injection is a procedure where one object supplies the dependencies of another object.
Here is an example of dependency injection in PHP:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php class Programmer { private $skills; public function __construct($skills){ $this->skills = $skills; } public function totalSkills(){ return count($this->skills); } } $createskills = array("PHP", "JQUERY", "AJAX"); $p = new Programmer($createskills); echo $p->totalSkills(); ?> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.