Skepsis Posted August 19, 2009 Share Posted August 19, 2009 Okay, so basically I have a calendar. In this calendar, it highlights the day we are on in the week with a certain color. What it also does, is checks if there was a forum post in any news category, and highlights that day blue. Well, I added a events system, which has events/birthdays. It now highlights events/birthdays in the same color news posts are highlighted. The original code was not meant for me to add this, but I have. The workaround I'd like to use, is set a "type" to the array, possibly a sub array including the type. I'm not sure if this is the proper way I should be going about this though. So basically, I'm asking for your input, and suggestions, on what I should do, or what I can do. http://pastebin.com/m740c013 The array looks like this as of now. $usable => Array (3) ( ['8'] = String(1) "1" ['17'] = String(1) "3" ['13'] = String(1) "1" ) 8,17,13 are the dates of the posts/events made. Well, minus 1, so the actual dates are, the 9th,18th,14th. I tried adding a variable to the code that stores the array into $usable, called $type, so I could just do: if(isset($usable[$i]) && $usable[$i]==TRUE && type == 'news') { But adding a variable seemed to give me trouble. What can I do? What's the best/efficient way of doing this, so if I add more modules in the future, I wouldn't stumble across this problem anymore? Thanks guys, hopefully I only need to come here for help and not go to any other place. Link to comment https://forums.phpfreaks.com/topic/171032-array-problems/ Share on other sites More sharing options...
rhodesa Posted August 19, 2009 Share Posted August 19, 2009 I would create Classes...so have a separate class for each type of item. Then you can have methods (or attributes) that return different info. For example, in your classes you can have a getColor() method that returns the bgcolor for that type of event. This allows you to easily add more types of events later on too. Link to comment https://forums.phpfreaks.com/topic/171032-array-problems/#findComment-902051 Share on other sites More sharing options...
Skepsis Posted August 21, 2009 Author Share Posted August 21, 2009 Sorry. I'm waiting until I master the basics of regular php, before I move onto object oriented code. I have a few classes to handle templating, caching, and database handling. How could I do it without making a whole entire class? Link to comment https://forums.phpfreaks.com/topic/171032-array-problems/#findComment-903012 Share on other sites More sharing options...
rhodesa Posted August 21, 2009 Share Posted August 21, 2009 then i would turn each element into an associate array to accomplish the same idea. So your array would turn into something like this: $usable => Array (3) ( ['8'] = Array ( ) ( ['type'] = String(4) "news" ['color'] = String(3) "red" ['title'] = String(18) "Something Happened" ) ['17'] = Array ( ) ( ['type'] = String(4) "post" ['color'] = String(4) "blue" ['title'] = String(13) "Some New Post" ) ['13'] = Array ( ) ( ['type'] = String(4) "news" ['color'] = String(3) "red" ['title'] = String(23) "Something Else Happened" ) ) Link to comment https://forums.phpfreaks.com/topic/171032-array-problems/#findComment-903317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.