Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6079729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:58:48+00:00 2026-05-23T10:58:48+00:00

Here is the PHP im working with: Below values from a database: $quote =

  • 0

Here is the PHP im working with:

Below values from a database:

$quote = 49;
$add_amp = 0;
$con_array = "3,2,1";


function calcAddAmp($mul)
{
    $add_amp = $add_amp + $mul*($quote);

}


$con_array = explode(",", $con);

for($i = 0; $i < count($con_array); $i++) { 
    switch ($fun) {
        case 1:
            calcAddAmp(.01);
            break;
        case 2:
            calcAddAmp(.05);
            break;
        case 3:
            calcAddAmp(.02);
            break;
        case 4:
            calcAddAmp(.09);
            break;
    }
}



$quote = $quote + $add_amp;

The issue is seen here:

echo $add_amp;

$add_amp returns 0, which makes $quote the same value as before, 49.

echo $quote;

I’m sure I am just writing this function incorrectly, but I can’t find where I went wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:58:48+00:00Added an answer on May 23, 2026 at 10:58 am

    Variables have function scope. Setting $add_amp inside a function does not automatically modify the variable by the same name outside the function. If you don’t return the value from the function it’s pointless. I’d simplify this whole unnecessary switch/function to this though:

    $multipliers = array(1 => .01, 2 => .05, 3 => .02, 4 => .09);
    
    foreach ($con_array as $con) {
        $add_amp += $multipliers[$con] * $quote;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the XML file i'm working on: <list> <activity>swimming</activity> <activity>running</activity> <activity>soccer</activity> </list> The index.php,
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
I'm kind of stuck with my heap sort here in php: <?php function heapSort($a,
I am completely stumped. Here is my php (CodeIgniter) code: function mod() { $uid
I'm working on one application ( using PHP, javascript ). Below is the short
I am working on a site which displays products from a database in a
PHP mysql database I have created a follow on question to this one here
Iam trying to parse rss feed from particular url... here is my php file
I was working in php java bridge and came across this problem. The below
For example, my goal is to test the code given here: PHP script that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.