Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

less lines

Posted on 2011-03-08
4
Medium Priority
?
252 Views
Last Modified: 2012-06-27
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
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 13

Expert Comment

by:darren-w-
ID: 35070538
I think your looking for Variable Variables :http://php.net/manual/en/language.variables.variable.php
0
 
LVL 13

Accepted Solution

by:
darren-w- earned 2000 total points
ID: 35070604
So:
<?php
$card = $realtype;
$$card += $p['debit']
?>

Open in new window


not tested
0
 
LVL 13

Expert Comment

by:darren-w-
ID: 35070647
and a working example:
<?php
$card = "Visa";
$$card +=1;
echo $Visa;
//returns 1
?>

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 35072076
thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question