array1 = array();
array2 = array();
Both arrays have values that come from the database;
Array2 contains a list of training, while array1 contains list of training already taken.
I want to compare array1 to array2 and retrieve the list of training that is not in the array1
Here is the snippet of the code i'm currently doing:
$query2 = "SELECT trainingName, rank FROM crewtraininglist WHERE crewId = '$crewId'";
$result2 = mysqli_query($conn, $query2);
$array = array();
while($row = mysqli_fetch_assoc($result2))
{
$rank = $row['rank'];
$training = $row['trainingName'];
$array[] = $row['trainingName'];
echo "<li>$training</li>";
//echo "<option value='{$row['name']}'>{$row['name']}</option>";
}
$array2 = array();
$query3 = "SELECT `trainingName`, `rank` FROM `traininglist` WHERE rank LIKE '%$rank%'";
$result3 = mysqli_query($conn, $query3);
while($row = mysqli_fetch_assoc($result3))
{
$array2[]=$row['trainingName'];
}
$array3 = array_diff($array,$array2);
print_r ($array3);
the output of array 1 is:
Array (
[0] => License + COC & Endrs.
[1] => Basic Training + COP
)
Output of Array2 is:
Array (
[0] => License + COC & Endrs.
[1] => Basic Training + COP
[2] => Personal Safety & Social Responsibility
[3] => Proficiency in Survival Craft & Rescue Boat (PSCRB) + COP
[4] => Advance Training in Firefighting (AFF) + COP
[5] => Medical Emergency First Aid (MEFA) + COP
[6] => Medical Care (MECA) + COP [7] => Radar Observing & Ploting Courses (ROC)
[8] => Operational Use of Automatic Radar Ploting Aids (ARPA)
[9] => Radar Simulator Course (RSC)
[10] => Ship Simulator & Bridge Team Work (SSBT) w/BRM
)