Jump to content

PLEASE SOMEBODY HELP ME SOLVE THESE SCENARIOS


ciriusrob

Recommended Posts

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... :confused:

 

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).

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...??? :confused:

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...??? :confused:

 

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

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 ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.