php:从日期范围中排除日期

I'm trying to figure out how to exclude certain dates from a date range I've set up. The date range works fine like so:

<?php $newBegin = new DateTime('6/30/2010');
$newEnd = new DateTime('7/12/2010');
$newEnd = $newEnd->modify( '+1 day' );

$newDaterange = new DatePeriod($newBegin, new DateInterval('P1D'), $newEnd);

foreach($newDaterange as $newDate){
    echo $newDate->format("jnY") . " ";
} ?>

Which prints the results like so:

3062010 172010 272010 372010 472010 572010 672010 772010 872010 972010 1072010 1172010 1272010

But the client will need to exclude certain dates from each date range, so I'd preferably like to input the dates like so: 7/2/2010 7/4/2010 8/4/2010 and exclude them from the date range. Is this at all possible? I'm not looking to exclude weekends or such, I can do that, just input a set of dates and exclude them from a date range. Any suggestions would be greatly appreciated!


Update:

As @hek2mgl asked for this, I've added a var_dump() of get_field('test_select'));

var_dump(get_field('test_select'));

Result:

array(2) { [0]=> string(8) "7/2/2010" [1]=> string(8) "

Full code (not working):

$newBegin = DateTime::createFromFormat('n/j/Y', '6/30/2010');
$newEnd = DateTime::createFromFormat('n/j/Y', '7/12/2010');
$newEnd = $newEnd->modify( '+1 day' );

$exclude = array();

// stores dates like so: 7/2/2010 7/3/2010
foreach(get_field('test_select') as $datestring) {
    $exclude []= new DateTime($datestring);
}

$newDaterange = new DatePeriod($newBegin, new DateInterval('P1D'), $newEnd);

foreach($newDaterange as $newDate){
    if(!in_array($newDate, $exclude)) {
        echo $newDate->format("jnY") . " ";
    }   
}

There is no way to exclude several dates within a range using the DatePeriod class. But you can use in_array() together with DateTime objects. This can lead to code like this:

$newBegin = new DateTime('6/30/2010');
$newEnd = new DateTime('7/12/2010');
$newEnd = $newEnd->modify( '+1 day' );

$exclude = array(
    new DateTime('7/2/2010'),
    new DateTime('7/4/2010'),
    new DateTime('8/4/2010')
);

$newDaterange = new DatePeriod($newBegin, new DateInterval('P1D'), $newEnd);

foreach($newDaterange as $newDate){
    if(!in_array($newDate, $exclude)) {
        echo $newDate->format("jnY") . " ";
    }   
} 

Output:

3062010 172010 372010 572010 672010 772010 872010 972010 1072010 1172010 1272010

Update:

In the comments you've asked how to translate an incoming list of date strings into DateTime objects which can be used in the $exclude array.

Example:

$exclude = array();

// stores dates like so: 7/2/2010 7/3/2010
foreach(get_field('test_select') as $datestring) {
    $exclude []= new DateTime::createFromFormat('n/j/Y', $datestring);
}

That's it. :)