Jump to content

IF in_array only check against the last value in my array ..


parapro

Recommended Posts

Can someone please help me figure this out:

 

I have a normal text file with 3 lines in it, every line contain one date i.e 12112011 (12.11-2011). I put the content of that file in an array, and want to compair the dates in the text file against the date generated from the loop. Problem is, i can only get a match for the last date listed in the text file no matter what.. If i have 4 dates in the file, it only style the last date.

 

Thanks!

 

--- CODE SNIPPET ---

 

$day_num = 1;

$days_in_month = 30;

$month = 11;

$year = 2011;

 

//Access the file containing already taken dates and load them in an array:

$date_array = file("test.txt");

 

//count up the days, untill we've done all of them in the month and check them against the dates in the text file:

while ($day_num <= $days_in_month) {

 

// Set the variable $date to be checked against the content of the array:

$date = $day_num . $month . $year;

 

if (in_array($date, $date_array)) {

            echo "<td class='color_green'>$day_num</td>";

//print_r($date_array);

}

else {

echo "<td>$day_num</td><br />";

}

 

$day_num++;

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.