Exclude arrays from arrays

Hi everyone
Sunday question here very PHP-oriented. I try to exclude some arrays from other arrays, but some of them are dates, other are normal ones, so I’m a bit lost.

=> Some ‘Monday’ and ‘Tuesday’ have ‘inactive’ class instead of ‘fmoon’
=> Some ‘Monday’ and ‘Tuesday’ have ‘inactive’ class and I don’t want to.

<?php 
if(date('D', strtotime($day)) === 'Mon' || date('D', strtotime($day)) === 'Tue' ) { echo 'id="ferie" ';}  <== exclude class="fmoon" from here
elseif (in_array($day, $ferie)) { echo 'id="ferie" ';} 
elseif (in_array($day, $fmoon)) { echo 'id="fmoon"';} 
if($day->month() != $month) echo ' class="inactive"' <== exclude 'Mon' and 'Tue' from here
?>

I think the way to do that is using array diff if I’m right, but manipulating dates and arrays is very mystical for me.

If I understood you correctly, that would be something like this:

<?php

$weekday = date('D', strtotime($day));

if(in_array($weekday, ['Mon', 'Tue'])) {
  echo 'id="ferie" ';
} else {
  if(in_array($day, $ferie)) {
    echo 'id="ferie" ';
  } elseif(in_array($day, $fmoon)) {
    echo 'id="fmoon" ';
  }
  
  if($day->month() != $month) echo 'class="inactive"';
}

?>

You’ve got the power ! But not really what I was looking for. Maybe my explanation was bad. So this is my illustration, I hope someone can help

On every webpage every “ID” has to be unique!

If I understand your code correctly, then some fields get the same “ID”.
Therefore I suggest to use “class” instead.

Good luck!

1 Like

Yep, I’d say the same. It also looks like every day can only have one class, so this can be simplified a bit:

<?php

$class = null;
if($day->month() != $month) {
  $class = 'inactive';
} elseif(in_array($day, $ferie) || in_array(date('D', strtotime($day)), ['Mon', 'Tue'])) {
  $class = 'ferie';
} elseif(in_array($day, $fmoon)) {
  $class = 'fmoon';
}

if($class) echo 'class="' . $class . '" ';

?>
1 Like

+1 for the ID !
This is the worst error I do every time !

And thank you very much Luka for your help your code works perfectly, in this order

<?php 
                          
                           $class = null;
if($day->month() != $month) {
  $class = 'inactive';
}  elseif(in_array($day, $fmoon)) {
  $class = 'fmoon';
} 
  elseif(in_array($day, $ferie) || in_array(date('D', strtotime($day)), ['Mon', 'Tue'])) {
  $class = 'ferie';
                           
    
}

if($class) echo 'class="' . $class . '" ';?>