Solved

less lines

Posted on 2011-03-08
4
245 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 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 …

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now