Results 1 to 14 of 14
  1. #1
    Join Date
    Mar 2002
    Location
    Texas
    Posts
    354

    PHP Challenge #3

    And here is your 3rd challenge. It's getting a little harder ;-)

    TODO: Write a script to print to the browser a different url every day of the month with a different category of url for each day of the week using a multi-dimensional array and no conditional statement

  2. #2
    Join Date
    Jan 2002
    Location
    Kuwait
    Posts
    679
    Can you explain a bit more with an example of what will happen in different days?
    Ahmad Alhashemi
    PHP, Apache, C, Python, Perl, SQL
    18 related BrainBench certificates

  3. #3
    Join Date
    Mar 2002
    Location
    Texas
    Posts
    354
    Make a multi-dimensional array with Differant categories of URLs. So say, monday gets a url from the car category, tuesday gets one from the hobbies category and so on. then next monday comes around and they get a differant URL from the car category.

  4. #4
    Join Date
    Jan 2002
    Location
    Kuwait
    Posts
    679
    Oh, ok. I get it now
    Ahmad Alhashemi
    PHP, Apache, C, Python, Perl, SQL
    18 related BrainBench certificates

  5. #5
    Join Date
    Jan 2002
    Location
    Kuwait
    Posts
    679
    PHP Code:
    <?php

    // Mon -- Cars
    $links[0][1]['url'] = 'Cars.com';
    $links[0][1]['name'] = 'http://www.cars.com/';

    $links[0][2]['url'] = 'Cars.com';
    $links[0][2]['name'] = 'http://www.cars.com/';

    $links[0][3]['url'] = 'Cars.com';
    $links[0][3]['name'] = 'http://www.cars.com/';

    $links[0][4]['url'] = 'Cars.com';
    $links[0][4]['name'] = 'http://www.cars.com/';

    $links[0][5]['url'] = 'Cars.com';
    $links[0][5]['name'] = 'http://www.cars.com/';

    // Tue -- Cars
    $links[1][1]['url'] = 'Cars.com';
    $links[1][1]['name'] = 'http://www.cars.com/';

    $links[1][2]['url'] = 'Cars.com';
    $links[1][2]['name'] = 'http://www.cars.com/';

    $links[1][3]['url'] = 'Cars.com';
    $links[1][3]['name'] = 'http://www.cars.com/';

    $links[1][4]['url'] = 'Cars.com';
    $links[1][4]['name'] = 'http://www.cars.com/';

    $links[1][5]['url'] = 'Cars.com';
    $links[1][5]['name'] = 'http://www.cars.com/';

    // Wed -- Cars
    $links[2][1]['url'] = 'Cars.com';
    $links[2][1]['name'] = 'http://www.cars.com/';

    $links[2][2]['url'] = 'Cars.com';
    $links[2][2]['name'] = 'http://www.cars.com/';

    $links[2][3]['url'] = 'Cars.com';
    $links[2][3]['name'] = 'http://www.cars.com/';

    $links[2][4]['url'] = 'Cars.com';
    $links[2][4]['name'] = 'http://www.cars.com/';

    $links[2][5]['url'] = 'Cars.com';
    $links[2][5]['name'] = 'http://www.cars.com/';

    // Thu -- Cars
    $links[3][1]['url'] = 'Cars.com';
    $links[3][1]['name'] = 'http://www.cars.com/';

    $links[3][2]['url'] = 'Cars.com';
    $links[3][2]['name'] = 'http://www.cars.com/';

    $links[3][3]['url'] = 'Cars.com';
    $links[3][3]['name'] = 'http://www.cars.com/';

    $links[3][4]['url'] = 'Cars.com';
    $links[3][4]['name'] = 'http://www.cars.com/';

    $links[3][5]['url'] = 'Cars.com';
    $links[3][5]['name'] = 'http://www.cars.com/';

    // Fri -- Cars
    $links[4][1]['url'] = 'Cars.com';
    $links[4][1]['name'] = 'http://www.cars.com/';

    $links[4][2]['url'] = 'Cars.com';
    $links[4][2]['name'] = 'http://www.cars.com/';

    $links[4][3]['url'] = 'Cars.com';
    $links[4][3]['name'] = 'http://www.cars.com/';

    $links[4][4]['url'] = 'Cars.com';
    $links[4][4]['name'] = 'http://www.cars.com/';

    $links[4][5]['url'] = 'Cars.com';
    $links[4][5]['name'] = 'http://www.cars.com/';

    // Sat -- Cars
    $links[5][1]['url'] = 'Cars.com';
    $links[5][1]['name'] = 'http://www.cars.com/';

    $links[5][2]['url'] = 'Cars.com';
    $links[5][2]['name'] = 'http://www.cars.com/';

    $links[5][3]['url'] = 'Cars.com';
    $links[5][3]['name'] = 'http://www.cars.com/';

    $links[5][4]['url'] = 'Cars.com';
    $links[5][4]['name'] = 'http://www.cars.com/';

    $links[5][5]['url'] = 'Cars.com';
    $links[5][5]['name'] = 'http://www.cars.com/';

    // Sun -- Cars
    $links[6][1]['url'] = 'Cars.com';
    $links[6][1]['name'] = 'http://www.cars.com/';

    $links[6][2]['url'] = 'Cars.com';
    $links[6][2]['name'] = 'http://www.cars.com/';

    $links[6][3]['url'] = 'Cars.com';
    $links[6][3]['name'] = 'http://www.cars.com/';

    $links[6][4]['url'] = 'Cars.com';
    $links[6][4]['name'] = 'http://www.cars.com/';

    $links[6][5]['url'] = 'Cars.com';
    $links[6][5]['name'] = 'http://www.cars.com/';


    // here comes the logic
    $link $links[intval(date('w'))][(intval(date('j')) % 5) + 1];

    echo 
    "<a href='$link[url]'>$link[name]</a>";

    ?>
    Ahmad Alhashemi
    PHP, Apache, C, Python, Perl, SQL
    18 related BrainBench certificates

  6. #6
    Join Date
    Mar 2002
    Posts
    1,003
    can someone do perl challange please?

  7. #7
    Join Date
    Dec 2001
    Posts
    1,372
    Originally posted by Shyne
    can someone do perl challange please?
    Or a cut and paste challenge...or even a watching paint dry challenge.

    Simon

  8. #8
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    248
    Originally posted by SimonMc


    Or a cut and paste challenge...or even a watching paint dry challenge.

    Simon
    I'd be up for that...

  9. #9
    Join Date
    Mar 2002
    Location
    Texas
    Posts
    354
    why is everyone here using intval when they do the date lol

  10. #10
    Join Date
    Dec 2001
    Posts
    1,372
    Originally posted by DoobyWho
    why is everyone here using intval when they do the date lol
    Ha Ha...because they are not as SMART as you...thats why.

    Simon

  11. #11
    Join Date
    Mar 2002
    Location
    Texas
    Posts
    354

  12. #12
    Join Date
    Jan 2002
    Location
    Kuwait
    Posts
    679
    Originally posted by DoobyWho
    why is everyone here using intval when they do the date lol
    Good habits die hard
    Ahmad Alhashemi
    PHP, Apache, C, Python, Perl, SQL
    18 related BrainBench certificates

  13. #13
    Join Date
    May 2002
    Posts
    78
    Code:
    $links[0][1]['url'] = 'Cars.com';
    $links[0][1]['name'] = 'http://www.cars.com/';
    So the url is Cars.com and the name is http://www.cars.com/ ?

  14. #14
    Join Date
    Mar 2002
    Location
    Texas
    Posts
    354
    lol. I didn't even notice that. Good job. I guess they had it backwords.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •