Skip to main content
  1. Tech
  2. Gadgets & Tech
  3. Tech Gear

Using functions in a PHP program (part 7)

See also

In this next article, we will discuss and demonstrate how to pass values in the correct order to a function. When a function is expected to perform a certain task and the values are not passed in a certain order, the function will not produce the correct result. The function always receives the values in the order they are passed as shown below:

function functionx ($x, $y, $z);


do stuff


Call the function as follows:

functionx ($var1, $var2, $var3, $var4);

function sets $w=$var1, $x=$var2, $y=$var3, and z=$var4).

The function definition to compute the sales tax should resemble code shown below:

function compute_salestax($amount, $clientState, $salestaxrate);


compute tax


$amount is the cost of the order, and $clientState is the state the client is located in. If you were to call the function as follows:

compute_salestax($clientState, $amount, $salestaxrate);

The function would use the value of the $clientState variable as the cost of the order, and the value of the $amount would be set as the $clientState variable. The function would not compute correctly.

Please Note:

I have installed and used a newer version of the Wampserver package for this program. The newer version is Wampserver (64 bits & PHP 5.5) 2.5, which includes the newer releases of .. Apache : 2.4.9 MySQL : 5.6.17 PHP : 5.5.12 PHPMyAdmin : 4.1.14 SqlBuddy : 1.3.3 XDebug : 2.2.5

Please refer to the following articles for the download, install, configuration and fixing the security hole.

Download, install and configure the web development environment (part 1)

Download, install and configure the web development environment (part 2)

Download, install and configure the web development environment (part 3)

Fixing the security hole that corresponds to the MySql privileged accounts

NOTE: As demonstrated in the previous programs, we used notepad a plain text editor. The PHP programs are stored on our web server, "C:\Wampserver\www." Please note the stored web server location.

Now let us create the PHP program, please follow the steps outlined below:

  1. Select and click "Start."
  2. Select and click "All Programs."
  3. Select and click "Accessories."
  4. Select and click "Notepad."
  5. Type the PHP code exactly as shown below.



<title>Calculate Sales Tax</title>


<body><h1>Calculate Sales Tax</h1>

<h3>Demonstrates passing values in the correct order to functions<h3>


$amount = 2000.00;

$salestaxrate = .07;

$clientState = "Virginia";

compute_salestax($amount, $clientState, $salestaxrate);

function compute_salestax($amount, $clientState, $salestaxrate)


$salestax = $amount * $salestaxrate;

print "$$salestax sales tax for the State of $clientState.<p />";





  1. Once you have type the entire program, Select "File," "Save As," and then go to the webroot of your server. For example, C:\Wampserver\www. Type Filename, salestaxcom.php," and then Select "Save."

In the next article of the Using functions in a PHP program (part 8); we will continue with Passing the right number of values to a function in a PHP Program.


Don't Miss

  • Unity
    'Assassin's Creed Unity' preview: Ubisoft comes home to its urban origins
    Games Preview
  • Kindle
    The new 'Kindle Unlimited' program could cause legal troubles for
    Tech Buzz
  • Destiny
    The 'Destiny' beta: 7 things we absolutely love about Bungie's new franchise
    Games Feature
  • iOS Backdoors
    iOS backdoors: Hidden items found in 600 million devices, is Apple spying on us?
  • Far Cry
    'Far Cry 4' exclusive: Animals, avalanches, oxygen, side content and much more
    Games Interview
  • iPhone Handle
    A young inventor thinks all iPhones should come with one of these gadgets