• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

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

0
rgb192
Asked:
rgb192
  • 3
1 Solution
 
darren-w-Commented:
I think your looking for Variable Variables :http://php.net/manual/en/language.variables.variable.php
0
 
darren-w-Commented:
So:
<?php
$card = $realtype;
$$card += $p['debit']
?>

Open in new window


not tested
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now