ciriusrob Posted October 23, 2010 Share Posted October 23, 2010 Can some PHP guru help me with this scenarios? I've been wondering around these for hours and can't find my way around it. Please... 1. Write a function in PHP that takes three parameters (representing day, month and year) and calculates the day/month/year of the following day (for example, if the parameter is 31/10/2010, the result should be 01/11/2010). No need to take into account leap years. You cannot use any date/time specific functions, you must do it "by hand" (no built-in functions).. 2. Write a function in PHP that takes a string and counts the number of occurrences of any given letter in it (for example, given the string "HELLO" as a parameter, there are two occurrences of "L", one of "H", one of "E", one of "O" and zero of any other character). Quote Link to comment https://forums.phpfreaks.com/topic/216632-please-somebody-help-me-solve-these-scenarios/ Share on other sites More sharing options...
Pikachu2000 Posted October 23, 2010 Share Posted October 23, 2010 Where exactly are you stuck? Post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/216632-please-somebody-help-me-solve-these-scenarios/#findComment-1125531 Share on other sites More sharing options...
ciriusrob Posted October 23, 2010 Author Share Posted October 23, 2010 I screwed up in a job interview when i was presented with these scenarios. I am a newbie in programming and I couldn't even get the logic or approach around the scenario let alone coding it. Can someone help by giving me the logic and approach in plain English so I'll try and code myself please...??? Quote Link to comment https://forums.phpfreaks.com/topic/216632-please-somebody-help-me-solve-these-scenarios/#findComment-1125536 Share on other sites More sharing options...
trq Posted October 23, 2010 Share Posted October 23, 2010 I DON'T APPRECIATE BEING YELLED AT!!!! Sounds like homework to me. We don't do homework. Quote Link to comment https://forums.phpfreaks.com/topic/216632-please-somebody-help-me-solve-these-scenarios/#findComment-1125538 Share on other sites More sharing options...
dreamwest Posted October 23, 2010 Share Posted October 23, 2010 I screwed up in a job interview when i was presented with these scenarios. I am a newbie in programming and I couldn't even get the logic or approach around the scenario let alone coding it. Can someone help by giving me the logic and approach in plain English so I'll try and code myself please...??? Your better off developing some of your own apps first and get some exp before you even think about building apps for a company..its just easier Quote Link to comment https://forums.phpfreaks.com/topic/216632-please-somebody-help-me-solve-these-scenarios/#findComment-1125541 Share on other sites More sharing options...
ignace Posted October 23, 2010 Share Posted October 23, 2010 function calc_next_day($day, $month, $year) { // 0 = January $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $day_count = $days_in_month[$month - 1]; if($day + 1 > $day_count) { $day = 1; if($month + 1 > 12) { $month = 1; ++$year; } else { ++$month; } } else { ++$day; } return "$day/$month/$year"; } function str_occur($string) { $string = preg_replace('/[^a-z]/i', '', $string); $string = str_split($string); return array_count_values($string); } A fun exercise You really can't do anything with it as they'll ask you questions about the code and you'll still end up screwed Quote Link to comment https://forums.phpfreaks.com/topic/216632-please-somebody-help-me-solve-these-scenarios/#findComment-1125545 Share on other sites More sharing options...
ciriusrob Posted October 23, 2010 Author Share Posted October 23, 2010 @ignace: i don't know how to thank you. i screwed up already but i think with this i can get to practice more and understand the concept of php programming. U R MAN.. Quote Link to comment https://forums.phpfreaks.com/topic/216632-please-somebody-help-me-solve-these-scenarios/#findComment-1125610 Share on other sites More sharing options...
ignace Posted October 23, 2010 Share Posted October 23, 2010 i don't know how to thank you Add an @copyright Ignace comment line above each function Quote Link to comment https://forums.phpfreaks.com/topic/216632-please-somebody-help-me-solve-these-scenarios/#findComment-1125659 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.