Solved

less lines

Posted on 2011-03-08
4
248 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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

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.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 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