Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Closed Thread
Classes - Array Variables
Old 10-27-2010, 11:15 AM Classes - Array Variables
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
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
evans123 is offline
View Public Profile Visit evans123's homepage!
 
 
Register now for full access!
Old 10-27-2010, 12:26 PM Re: Classes - Array Variables
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
Problem has been resolved now using $this->notifications[$key] etc.
evans123 is offline
View Public Profile Visit evans123's homepage!
 
Closed Thread     « Reply to Classes - Array Variables
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31871 seconds with 12 queries