Reputation: 7847
I am trying to echo certain values if the variable $cardtype ==
$paymentmethod = if( $cardtype == 'visa' ) echo 'VSA';
elseif ( $cardtype == 'mastercard' ) echo 'MSC';
elseif ( $cardtype == 'mastercard' ) echo 'MSC';
elseif ( $cardtype == 'maestro' ) echo 'MAE';
elseif ( $cardtype== 'amex' ) echo 'AMX';
How would I do this???
Upvotes: 0
Views: 212
Reputation: 157989
for your own code, you have to just remove strange $paymentmethod =
from the beginning.
if( $cardtype == 'visa' ) echo 'VSA';
elseif ( $cardtype == 'mastercard' ) echo 'MSC';
elseif ( $cardtype == 'maestro' ) echo 'MAE';
elseif ( $cardtype== 'amex' ) echo 'AMX';
it will work too.
Upvotes: 0
Reputation: 163318
$types = array( 'visa' => 'VSA', 'mastercard' => 'MSC',
'maestro' => 'MAE', 'amex' => 'AMX' );
echo ( isset( $types[ $cardtype ] ) ) ? $types[ $cardtype ] : 'Wrong card type';
Upvotes: 6
Reputation: 4598
You could use a function containing a switch statement for this:
function GetPaymentMethod( $cardtype )
{
switch( $cardtype )
{
case 'visa':
return 'VSA';
case 'mastercard':
return 'MSC';
case 'maestro':
return 'MAE';
case 'amex':
return 'AMX';
default:
return '<Invalid card type>';
}
}
Test:
echo GetPaymentMethod( 'visa' ); // VSA
Upvotes: 2
Reputation: 7775
Here is one way to do it:
switch($cardtype) {
case 'visa':
echo 'VSA';
break;
case 'mastercard':
echo 'MSC';
break;
}
And so on
Upvotes: 0