Last active
August 29, 2015 14:21
-
-
Save joelbrennan0/93750c1e96b16d18907b to your computer and use it in GitHub Desktop.
PHP CLASSES - Basics of a class:
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 Task { | |
public $title; | |
public $description; | |
public function __construct($title, $description) { | |
$this->title = $title; | |
$this->description = $description; | |
} | |
} | |
?> |
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 | |
/*=================================== | |
CLASSES - a hypothetical task list | |
===================================*/ | |
include 'Task.php'; | |
$task1 = new Task('Milk', 'get two pints of milk from the shop'); | |
$task2 = new Task('Traniers', 'buy a new pair of running shoes'); | |
$tasks = array($task1, $task2); | |
?> | |
<h1>Tasks</h1> | |
<?php foreach ($tasks as $task) : ?> | |
<h2><?php echo $task->title ?></h2> | |
<p><?php echo $task->description ?></p> | |
<?php endforeach; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment