<?php
// ----------------------------------------------------------------------------
// Script Author: Robert Holland
// Script Name: arrayitemmatch.php
// Creation Date: Fri Nov 22 2024 11:01:29 GMT-0700 (MST)
// Last Modified:
// Copyright (c)2024
// Version: 1.0.0
// Purpose: Match items between two arrays. Similar to my radiation_onc function.
// ----------------------------------------------------------------------------
//The function arrayitemmatch will display matching items between two arrays.
//It takes two options 1, or 2. Default is 1.
//Option 1 will display the matching items and a blank space for items that do not match.
//Option 2 will display the matching items only.
function arrayitemmatch($array1itemname, $array2, $array2itemname1, $array2itemname2, $array2itemname3, $option = 1) {
if ($option == 1) {
foreach ($array2 as $array2item) {
if ($array2item[$array2itemname1] == $array1itemname) { // If treatment code matches the radiation code.
return "<tr><td>" . $array2item[$array2itemname3] . "</td><td>" . $array2item[$array2itemname2] . "</td><td>" . $array2item[$array2itemname1] . "</td></tr>"; // Return the treatment date and result.
}
}
return "<tr><td> </td><td> </td><td> </td></tr>"; // If no match, return empty.
} elseif ($option == 2) {
foreach ($array2 as $array2item) {
if ($array2item[$array2itemname1] == $array1itemname) { // If treatment code matches the radiation code.
return "<tr><td>" . $array2item[$array2itemname3] . "</td><td>" . $array2item[$array2itemname2] . "</td><td>" . $array2item[$array2itemname1] . "</td></tr>"; // Return the treatment date and result.
}
}
// return ""; // If no match, return empty.
}
}
// Example arrays BEGIN:
$dateGroup = [ // dateGroup array.
["TREATMENTDATE" => "2024-11-22", "TREATMENTRESULT" => "Result1", "TREATMENTCD" => "A123"],
["TREATMENTDATE" => "2024-11-21", "TREATMENTRESULT" => "Result2", "TREATMENTCD" => "B456"],
["TREATMENTDATE" => "2024-11-20", "TREATMENTRESULT" => "Result3", "TREATMENTCD" => "C789"],
["TREATMENTDATE" => "2024-11-21", "TREATMENTRESULT" => "Result4", "TREATMENTCD" => "B457"],
["TREATMENTDATE" => "2024-11-20", "TREATMENTRESULT" => "Result5", "TREATMENTCD" => "E654"]
];
$radiationCodes = [ // radiationCodes array.
["RAD_CD" => "A123", "RAD_THERAPY_TYPE" => "XRAY"],
["RAD_CD" => "B456", "RAD_THERAPY_TYPE" => "PROTON"],
["RAD_CD" => "C788", "RAD_THERAPY_TYPE" => "PHOTON"],
["RAD_CD" => "D321", "RAD_THERAPY_TYPE" => "PROTON"],
["RAD_CD" => "E654", "RAD_THERAPY_TYPE" => "PHOTON"]
];
// Example arrays END:
// Example usage BEGIN:
echo "<table border='1'>";
foreach ($radiationCodes as $rcode) { // Each item in the radiationCodes array.
// echo arrayitemmatch($rcode['columnname'], $dateGroup, "columnname3", "columnname2", "columnname1", 2); // Match each item in the radiationCodes array with $dateGroup.
echo arrayitemmatch($rcode['RAD_CD'], $dateGroup, "TREATMENTCD", "TREATMENTRESULT", "TREATMENTDATE", 1); // Match each item in the radiationCodes array with $dateGroup.
}
echo "</table>";
//arrayitemmatch($rcode['columnname'], $dateGroup, "columnname3", "columnname2", "columnname1", 2);
// Example usage END:
?>