FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » comparing arrays
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: comparing arrays [message #181043 is a reply to message #181042] Sun, 07 April 2013 13:59 Go to previous messageGo to previous message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma:
Senior Member
On 4/7/2013 9:37 AM, Thomas 'PointedEars' Lahn wrote:
> bill wrote:
>
>> I need to see if a patient has appointments with a
>> psychotherapist and a physician on the same day.
>>
>> I request the schedule of each therapist and each physician as
>> arrays of arrays:
>> time, patient_number, duration (note, the therapist/physician id
>> is not in the array)
>> They are non-associative arrays (numeric keys)
>> I might have 1..n physicians and 1..n therapists
>> I can generate arrays of physicians and arrays of therapists
>>
>> Option 1 is a nightmare of nested foreachs
>>
>> I am sure there must be an array function that will permit this
>> check.
>
> I am quite sure there isn't.
>
>> AFAIK, the _intersect functions require the same date in
>> all, when what I want is "any".
>>
>> my current thought is to create arrays of just pt_number, merge
>> the physician arrays, merge the therapist arrays, array_flip to
>> move the values to keys and then array_intersect.
>
> A merge will destroy the association between patient, date, and doctor.
>
>> But, before I try that I welcome any suggestions.
>
> You should probably do this in a relational database. But if you
> absolutely must do it in PHP, you can determine what the keys of your data
> are, and in which order you need them: the patient, the date, or the doctor.
>
> Then you can build from the records a “multi-dimensional array” (for lack of
> a better word) from which becomes apparent where there are schedule
> collisions. You can take advantage of the fact that PHP builds “multi-
> dimensional arrays” automatically if you add another index expression.
>
> For example, in a loop,
>
> $appointments[$patient_id][$date] = $doctor;
>
> would store the information that the patient with ID $patient_id has an
> appointment with $doctor on $date. Obviously it is very easy then to
> organize the data by different primary keys in different “multi-dimensional
> arrays” (which themselves may be elements of yet another array, to avoid
> extra variables). If an element of an array with an index already exists,
> there is the collision.
>
>
> HTH
It is actually slightly simpler as I only need to check for
"today". But is more complex in that I have two classes for
"doctor:" therapist or physician.

By doing it in a db are you suggesting a temporary table, or
using the tables I have ?

bill
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Need help with stripping characters from numbers in array
Next Topic: Connecting to MySQL server....
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Dec 18 04:30:47 GMT 2024

Total time taken to generate the page: 0.04256 seconds