Web Hosting Talk







View Full Version : PHP Challenge #3


DoobyWho
08-10-2002, 12:17 PM
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

Ahmad
08-10-2002, 12:39 PM
Can you explain a bit more with an example of what will happen in different days?

DoobyWho
08-10-2002, 12:44 PM
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.

Ahmad
08-10-2002, 02:11 PM
Oh, ok. I get it now :)

Ahmad
08-10-2002, 02:34 PM
<?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>";

?>

Shyne
08-10-2002, 02:51 PM
can someone do perl challange please?

SimonMc
08-10-2002, 03:10 PM
Originally posted by Shyne
can someone do perl challange please?

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

Simon

citrus
08-10-2002, 04:08 PM
Originally posted by SimonMc


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

Simon

I'd be up for that...:nuts:

DoobyWho
08-10-2002, 04:11 PM
why is everyone here using intval when they do the date :angry: lol

SimonMc
08-10-2002, 04:20 PM
Originally posted by DoobyWho
why is everyone here using intval when they do the date :angry: lol

Ha Ha...because they are not as SMART as you...thats why.

Simon

DoobyWho
08-10-2002, 04:24 PM
:rolleyes:

Ahmad
08-11-2002, 02:25 PM
Originally posted by DoobyWho
why is everyone here using intval when they do the date :angry: lol

Good habits die hard :stickout

vox-fred
08-11-2002, 03:28 PM
$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/ ?

DoobyWho
08-11-2002, 03:43 PM
lol. I didn't even notice that. Good job. I guess they had it backwords.