Comparing two arrays

From: John Smith (kevin4205_at_comcast.net)
Date: 02/25/05


Date: Fri, 25 Feb 2005 05:58:12 -0800

I got stuck on this and my brain is not working correctly. I am somewhat new
at PHP, and programming in general, so that is my excuse.
I am making an online reservations web page.

I have an array $rooms that has a list of room numbers.

I have another array $taken that has a list of the rooms that are not
available.

I want to find out which rooms are available by subtracting the items in the
$taken array from the $rooms array.

For instance,

If rooms has 1, 2, 3, 4, 5, 6, 7, 8

And the taken array has 3, 5, 8

How do I write the code so that I end up with an array called $available
that would have the remaining rooms 1, 2, 4, 6, 7?

Any help would be tremendously appreciated.

Thanks,
Kevin



Relevant Pages

  • Re: Need help on PHP for MPE/ix
    ... Here is the syntax of the dbupdate intrinsic in PHP: ... assoc array of item values) ... Please let me know if you have any more suggesstions to solve this problem. ... Pavan Kumar Rati wrote: ...
    (comp.sys.hp.mpe)
  • Re: Using a RegEx as a "variable" WITHIN an array?
    ... believe the PHP one is also based upon. ... combination of 1 or more numerics in this instance would give you your ... add this to your array - you could then do a pattern match on the array ... > Dim selCriteria as String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Need help on PHP for MPE/ix
    ... If one item is an array, it must be declared as such in the list ... So, please show us the declaration of the record buffer, and its ... Of Pavan Kumar Rati ... Need help on PHP for MPE/ix ...
    (comp.sys.hp.mpe)
  • Re: attempting to return values from array from w/in a function
    ... What I get is an array w/ only the most recent array entry. ... I am new to PHP & do not have formal scripting ... you end up comparing strings, but the test you mean probably is simply: ... case 1: {codeblock} ...
    (comp.lang.php)
  • Re: need to send email to 1000 addresses (currently in MS Excel)- whats the best way to do that, cre
    ... > coding each line as an array then looping through the array with mail. ... >> don't post a question that doesn't have anything to remotely do with PHP, ... one huge string) and then it splits that string into an array of arrays. ... CC it, or even better, BCC it so that those being emailed can't ...
    (comp.lang.php)