less lines

I want to do this in less lines


something like this

${$variableName}+=p['debit']
switch($realtype){

case 'Amazon':
$Amazon+=$p['debit'];
break;
case 'Amex':
$Amex+=$p['debit'];
break;
case 'Cash':
$Cash+=$p['debit'];
break;
case 'Discover':
$Discover+=$p['debit'];
break;
case 'Maestro':
$Maestro+=$p['debit'];
break;
case 'Mastercard':
$Mastercard+=$p['debit'];
break;
case 'Paypal':
$Paypal+=$p['debit'];
break;
case 'Solo':
$Solo+=$p['debit'];
break;
case 'Visa':
$Visa+=$p['debit'];
break;
case 'Wire':
$Wire+=$p['debit'];
break;
default:
break;
}

Open in new window

LVL 1
rgb192Asked:
Who is Participating?
 
darren-w-Commented:
So:
<?php
$card = $realtype;
$$card += $p['debit']
?>

Open in new window


not tested
0
 
darren-w-Commented:
I think your looking for Variable Variables :http://php.net/manual/en/language.variables.variable.php
0
 
darren-w-Commented:
and a working example:
<?php
$card = "Visa";
$$card +=1;
echo $Visa;
//returns 1
?>

Open in new window

0
 
rgb192Author Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.