I am making a notification class for my website. I want to be able to add, remove and show the notifications. I have completed the adding of the notifications to a class array variable called $notifications. All the notifications are stored as an array and i want to be able to use foreach to output these notifications when the $notifications->showNotifications() function is executed.
The one problem that i have is im not sure on how i can reference to the array in the $notifications variable.
PHP Code:
class Notification { var $notifications = array(); var $notifications_count = 0; /* * Add a notification * A notification will only show up if it has been added before the showNotifications() function has been executed. */ function addNotification($type, $content) { $notification_types = array('error', 'warning'); /* * Check to see if notification type is allowed and then process notification. * If notification is not configured properly you will receive a warning message. */ $this->notifications_count = $this->notifications_count + 1; if(in_array($type, $notification_types) && !empty($content)) $this->notifications = array_push($this->notifications,array('type' => $type, 'content' => ucfirst(strtolower($content)))); else $this->notifications = array_push($this->notifications,array('type' => 'warning', 'content' => 'Warning notification has been configured incorrectly.')); } /* * Remove a notification * You can only remove a notification before it has been outputted via the showNotifications() function. */ function removeNotification() { } /* * Show notifications * Once the notifications have been shown they are removed from the $notifications array variable. */ function showNotifications() { $this->notifications; } };
/* Initialize mailer object */ $notification = new Notification;
|