0

The following foreach outputs a list of dates, however I do not want to display any that have a Saturday or a Sunday in the output. What I've got removes any output containing Saturday but I can't seem to remove the Sunday, I've tried using the or || in various places but with no luck. I'm formatting the date into this format - 'Monday 9 December 2019'

foreach($data['Appointments'] as $dates)
    $readabledate = date("l j F Y ",strtotime(date($dates['Starttime'])));

    if (strpos($readabledate, 'Saturday') === false) {  
    echo $readabledate; //lists all dates
    }

}

1 Answer 1

2

You have to use &&, both results have to be false. One will always be true.

<?php

$data['Appointments'][] = array('Starttime' => "2019-12-06");
$data['Appointments'][] = array('Starttime' => "2019-12-07");
$data['Appointments'][] = array('Starttime' => "2019-12-08");
$data['Appointments'][] = array('Starttime' => "2019-12-09");


foreach($data['Appointments'] as $dates){
    $readabledate = date("l j F Y ",strtotime(date($dates['Starttime'])));

    if (strpos($readabledate, 'Saturday') === FALSE && strpos($readabledate, 'Sunday') === FALSE ) {  
    echo $readabledate . "\n"; //lists all dates
    }

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.