PHP If/ELSE or Switch/Case Statement

algorithm, php, switch-statement

Solution

<?php
$messages = array('10000' => 'No Visa Required', '01000' => 'Visa can be obtained on Arrival');
$no_required = '0';
$on_arrival = '1';
$schengen_visa = '0';
$uk_visa = '0';
$usa_visa = '0';

$result = "$no_required$on_arrival$schengen_visa$uk_visa$usa_visa";
if(array_key_exists($result, $messages)){
 echo $messages[$result]; //Visa can be obtained on Arrival
}

?>

Problem

I have give inputs which can be either 1 or 0 ``` $no_required $on_arrival $schengen_visa $uk_visa $usa_visa ``` I have the Following Cases and i want to display unique message back to the user for each one of them ``` a b c d e 1 0 0 0 0 No Visa Required 0 1 0 0 0 Visa can be obtained on Arrival 0 0 1 0 0 You need Schengen Visa 0 0 0 1 0 You need UK visa 0 0 0 0 1 You need US visa 0 0 1 1 1 You need Either of the Visas 0 0 1 1 0 You need Schengen/UK visa 0 0 1 0 1 You need Schengen/US visa 0 0 0 1 1 You need USA/UK visa ``` Where A B C D E F are the above variables. Which is the best and optimized way to display the results.

Original source