1

I have the following array:

$avail = array($this->item->extraFields->RoomONEDateAvailable->value, $this->item->extraFields->RoomTWODateAvailable->value, $this->item->extraFields->RoomTHREEDateAvailable->value, $this->item->extraFields->RoomFOURDateAvailable->value, $this->item->extraFields->RoomFIVEDateAvailable->value, $this->item->extraFields->RoomSIXDateAvailable->value, $this->item->extraFields->RoomSEVENDateAvailable->value, $this->item->extraFields->RoomEIGHTDateAvailable->value, $this->item->extraFields->RoomNINEDateAvailable->value, $this->item->extraFields->RoomTENDateAvailable->value);

These are the actual values:

Array ( [0] => Thursday, 01 January 1970 [1] => Thursday, 03 September 2015 [2] => Thursday, 01 January 1970 [3] => Thursday, 01 January 1970 [4] => Thursday, 01 January 1970 [5] => Thursday, 01 January 1970 [6] => Thursday, 01 January 1970 [7] => Thursday, 01 January 1970 [8] => Thursday, 01 January 1970 [9] => Thursday, 01 January 1970 ) 

I need to remove all the 'Thursday, 01 January 1970' dates from the array, so it only contains valid dates, how can I do this please?

3 Answers 3

3

Try:

$avail = array_diff($avail, array('Thursday, 01 January 1970'));
Sign up to request clarification or add additional context in comments.

1 Comment

this is a nice solution! wow, there are so many array functions in PHP - I'll never know them all.
1

you don't need to rebuild your array, you can remove array entries with unset()[reference].
update: you don't need a reference here, you can work with the corresponding array directly:

foreach($avail as $key => $val)
{
    if($val == "Thursday, 01, January 1970")
        unset($avail[$key]);
}

var_dump($avail);

this is tested and should work for you.

Comments

0

You can use the array_keys() functions, adding the option to search for a specific value, like this:

array_keys($array, "Thursday, 01 January 1970")

It will return an array of matching index, which you should unset from the original array.

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.